Created
January 20, 2012 14:32
-
-
Save AlexParamonov/1647601 to your computer and use it in GitHub Desktop.
This gist will lich all your free time, so be warned!
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 Q | |
def add | |
puts "added to Q" | |
end | |
end | |
queue = Q.new | |
notifier = Module.new do | |
def add(*args) | |
super | |
puts "i am from notifier!" | |
end | |
alias_method :push, :add | |
alias_method :<<, :add | |
end | |
queue.send :extend, notifier | |
# Ok, lets try: | |
queue.add | |
# Ruby 1.9 | |
# added to Q | |
# i am from notifier! | |
# Ruby 1.8 | |
# added to Q | |
# i am from notifier! | |
# what about our aliases? | |
queue.push | |
# Ruby 1.9 | |
# added to Q | |
# i am from notifier! | |
# Ruby 1.8 | |
# test.rb:11:in `push': super: no superclass method `add' for #<Q:0x1dbf0f0> (NoMethodError) | |
# from test.rb:19 | |
# WTF?! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment