Created
September 4, 2012 15:33
-
-
Save myronmarston/3622456 to your computer and use it in GitHub Desktop.
Weirdness with defined? on method chains
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
def method_missing(name, *args) | |
puts "in #{name}" | |
self | |
end | |
def respond_to_missing?(name, include_private) | |
true | |
end | |
end | |
k = Foo.new | |
puts defined?(k.a) | |
puts defined?(k.a.b) | |
puts defined?(k.a.b.c) | |
puts defined?(k.a.b.c.d) | |
puts defined?(k.a.b.c.d.e) | |
puts defined?(k.a.b.c.d.e.f) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➜ ruby --version | |
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0] | |
➜ ruby defined.rb | |
method | |
in a | |
method | |
in a | |
in a | |
in b | |
method | |
in a | |
in a | |
in b | |
in a | |
in b | |
in c | |
method | |
in a | |
in a | |
in b | |
in a | |
in b | |
in c | |
in a | |
in b | |
in c | |
in d | |
method | |
in a | |
in a | |
in b | |
in a | |
in b | |
in c | |
in a | |
in b | |
in c | |
in d | |
in a | |
in b | |
in c | |
in d | |
in e | |
method |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment