Skip to content

Instantly share code, notes, and snippets.

@captainpete
Created April 8, 2010 23:54
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 captainpete/360695 to your computer and use it in GitHub Desktop.
Save captainpete/360695 to your computer and use it in GitHub Desktop.
# At first glance, this doesn't seem so useful.
def a
def b
'you called b'
end
'b is now defined'
end
# > b
# NameError: undefined local variable or method `b'...
# > a
# => "b is now defined"
# > b
# => "you called b"
# but taken another way...
def enter_building
def enter_building
"enter building"
end
# method is now redefined for subsequent calls
"open roller door, " + enter_building
end
# > enter_building
# => "open roller door, enter building"
# > enter_building
# => "enter building"
# > enter_building
# => "enter building"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment