Created
August 18, 2010 13:47
-
-
Save nusco/534776 to your computer and use it in GitHub Desktop.
Spell: Ghost Method
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
# =================== | |
# Spell: Ghost Method | |
# =================== | |
# Respond to a message that doesn’t have an associated method. | |
class C | |
def method_missing(name, *args) | |
name.to_s.reverse | |
end | |
end | |
obj = C.new | |
obj.my_ghost_method # => "dohtem_tsohg_ym" | |
# For more information: http://www.pragprog.com/titles/ppmetr/metaprogramming-ruby |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment