Skip to content

Instantly share code, notes, and snippets.

@jaydonnell
Created December 30, 2009 21:15
Show Gist options
  • Save jaydonnell/266395 to your computer and use it in GitHub Desktop.
Save jaydonnell/266395 to your computer and use it in GitHub Desktop.
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