Created
December 30, 2009 21:15
-
-
Save jaydonnell/266395 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Jay | |
def talk | |
puts 'hi' | |
end | |
end | |
def make_say(msg, &b) | |
Jay.send(:alias_method, :orig_talk, :talk) | |
Jay.send(:define_method, :talk) { puts msg } | |
begin | |
yield | |
ensure | |
Jay.send(:alias_method, :talk, :orig_talk) | |
end | |
end | |
make_say("bye") { | |
j = Jay.new | |
j.orig_talk | |
j.talk | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment