10 Things Every Java Programmer Should Know About Ruby

What Kind of Differences?

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