Class: PolyDelegate::Delegator

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

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ Delegator

Returns a new instance of Delegator.



12
13
14
# File 'lib/poly_delegate/delegator.rb', line 12

def initialize(obj)
  @__delegated_object__ = obj
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block)



16
17
18
19
# File 'lib/poly_delegate/delegator.rb', line 16

def method_missing(name, *args, &block)
  super unless @__delegated_object__.respond_to?(name)
  @__delegated_object__.__send__(name, self, *args, &block)
end

Instance Method Details

#__undelegated_get__(sym)



29
30
31
# File 'lib/poly_delegate/delegator.rb', line 29

def __undelegated_get__(sym)
  __instance_variable_get__(sym)
end

#__undelegated_set__(sym, value)



33
34
35
# File 'lib/poly_delegate/delegator.rb', line 33

def __undelegated_set__(sym, value)
  __instance_variable_set__(sym, value)
end

#instance_variable_get(sym)



21
22
23
# File 'lib/poly_delegate/delegator.rb', line 21

def instance_variable_get(sym)
  @__delegated_object__.instance_variable_get(sym)
end

#instance_variable_set(sym, value)



25
26
27
# File 'lib/poly_delegate/delegator.rb', line 25

def instance_variable_set(sym, value)
  @__delegated_object__.instance_variable_set(sym, value)
end