Module: Bookkeeping::Proxy

Defined in:
lib/bookkeeping/proxy.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



8
9
10
# File 'lib/bookkeeping/proxy.rb', line 8

def method_missing(name, *args, &block)
  @caller.send(name, *args, &block)
end

Instance Method Details

#caller=(context) ⇒ Object



3
4
5
6
# File 'lib/bookkeeping/proxy.rb', line 3

def caller= context
  @caller = context
  exec_in_caller(context)
end

#exec_in_caller(context) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/bookkeeping/proxy.rb', line 16

def exec_in_caller(context)
  return unless context

  context.instance_variables.each do |ivar|
    value_from_caller = context.instance_variable_get(ivar)
    self.instance_variable_set(ivar, value_from_caller)
  end
end

#respond_to?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/bookkeeping/proxy.rb', line 12

def respond_to?(name, include_private = false)
  @caller.respond_to?(name) || super
end