Created
March 12, 2014 16:08
-
-
Save keithrbennett/9510095 to your computer and use it in GitHub Desktop.
Illustrates that a method can contain a method definition, but that the inner defined method becomes a regular instance method, rendering the code nesting misleading.
This file contains 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
#!/usr/bin/env ruby | |
class C | |
def foo | |
def bar | |
puts "I am bar." | |
end | |
bar | |
end | |
end | |
# nil | |
c = C.new | |
c.foo | |
# I am bar. | |
c.bar | |
# I am bar. | |
puts C.public_instance_methods.include?(:bar) | |
# true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment