Created
December 28, 2009 18:58
-
-
Save Peeja/264845 to your computer and use it in GitHub Desktop.
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
# Dan Chak, author of O'Reilly's "Enterprise Rails" thinks that Ruby has inner methods. | |
# See "Enterprise Rails", pg. 140. | |
class Foo | |
def bar | |
"outer bar" | |
end | |
def foo | |
# Dan Chak thinks this can only be called from within #foo. | |
def bar | |
"'inner' bar" | |
end | |
bar | |
end | |
end | |
# Dan Chak is wrong. | |
puts Foo.new.bar | |
puts Foo.new.foo | |
puts Foo.new.bar | |
# "def" adds a method to a class. There is no notion of scope. | |
# The first Foo.new.bar runs the first #bar method, and the call | |
# to Foo.new.foo redefines #bar before the second call. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment