Class: ReferenceTracking::IvarProxy

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

Instance Method Summary collapse

Constructor Details

#initialize(owner, name, object, references) ⇒ IvarProxy

Returns a new instance of IvarProxy.



5
6
7
8
9
10
# File 'lib/reference_tracking/ivar_proxy.rb', line 5

def initialize(owner, name, object, references)
  @owner      = owner
  @name       = name
  @object     = object
  @references = references
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



16
17
18
# File 'lib/reference_tracking/ivar_proxy.rb', line 16

def method_missing(method, *args, &block)
  respond_to?(method) ? __track__(method, *args, &block) : super
end

Instance Method Details

#__track__(method, *args, &block) ⇒ Object



20
21
22
23
24
# File 'lib/reference_tracking/ivar_proxy.rb', line 20

def __track__(method, *args, &block)
  @references << [@object, nil]
  @owner.instance_variable_set(@name, @object)
  @object.send(method, *args, &block)
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/reference_tracking/ivar_proxy.rb', line 12

def respond_to?(method)
  @object.respond_to?(method)
end