Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Proxy
  def initialize(target_object)
    @object = target_object
    @messages = []
  end

  def method_missing(method_name, *args, &block)
    @messages.push method_name
    @object.send method_name, *args, &block
  end

  def messages
    @messages
  end

  def called?(method_name)
    @messages.include? method_name
  end

  def number_of_times_called(method_name)
    @messages.select {|x| x == method_name}.size
  end
end