Class: RecursiveSpy

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

Defined Under Namespace

Classes: MethodInvocation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRecursiveSpy

Returns a new instance of RecursiveSpy.



4
5
6
# File 'lib/recursive_spy.rb', line 4

def initialize
  @calls = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/recursive_spy.rb', line 8

def method_missing(method, *args)
  value = self.class.new
  @calls[method] ||= []
  @calls[method] << MethodInvocation.new(
    value,
    args
  )
  value
end

Instance Attribute Details

#callsObject (readonly)

Returns the value of attribute calls.



2
3
4
# File 'lib/recursive_spy.rb', line 2

def calls
  @calls
end