Skip to content

Instantly share code, notes, and snippets.

@keithrbennett
Created March 12, 2014 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keithrbennett/9510095 to your computer and use it in GitHub Desktop.
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.
#!/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