Skip to content

Instantly share code, notes, and snippets.

@Peeja
Created December 28, 2009 18:58
Show Gist options
  • Save Peeja/264845 to your computer and use it in GitHub Desktop.
Save Peeja/264845 to your computer and use it in GitHub Desktop.
# 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