Class: Mementus::BindingDelegator

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

Instance Method Summary collapse

Constructor Details

#initialize(instance, scope) ⇒ BindingDelegator

Returns a new instance of BindingDelegator.



3
4
5
6
# File 'lib/mementus/binding_delegator.rb', line 3

def initialize(instance, scope)
  @instance = instance
  @scope = scope.eval('self')
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



8
9
10
11
12
13
14
# File 'lib/mementus/binding_delegator.rb', line 8

def method_missing(name, *args, &block)
  if @instance.respond_to?(name)
    @instance.send(name, *args, &block)
  else
    @scope.send(name, *args, &block)
  end
end

Instance Method Details

#respond_to_missing?(name) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/mementus/binding_delegator.rb', line 16

def respond_to_missing?(name)
  @scope.respond_to?(name) || @instance.respond_to?(name)
end