10 Things Every Java Programmer Should Know About Ruby | [ Prev | Home | Next ] |
Consider the following class. It defines an object that is able to record all the messages ever sent to it, and then playback those messages to another object.
class VCR
def initialize
@messages = []
end
def method_missing(method, *args, &block)
@messages << [method, args, block]
end
def play_back_to(obj)
@messages.each do |method, args, block|
obj.send(method, *args, &block)
end
end
end
O'REILLY® OSCON 2005 | Copyright 2005 by Jim Weirich (All Rights Reserved) |