Class: MethodSpy

Inherits:
Object
  • Object
show all
Defined in:
lib/util.rb

Instance Method Summary collapse

Constructor Details

#initialize(delegate, &block) ⇒ MethodSpy

Returns a new instance of MethodSpy.


17
18
19
20
# File 'lib/util.rb', line 17

def initialize(delegate, &block)
  @delegate = delegate
  @filter = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args, &block) ⇒ Object


22
23
24
25
26
# File 'lib/util.rb', line 22

def method_missing(symbol, *args, &block)
  result = @delegate.send(symbol, *args, &block)
  p [symbol, args, result, block] if @filter && @filter.call(symbol.to_s)
  result
end