Class: MotionBindable::DelegateProxy

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

Overview

This allows objects to register multiple delegates

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*initial_delegates) ⇒ DelegateProxy

Returns a new instance of DelegateProxy.



8
9
10
# File 'lib/motion_bindable/delegate_proxy.rb', line 8

def initialize(*initial_delegates)
  self.delegates = initial_delegates
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



12
13
14
15
16
17
18
19
# File 'lib/motion_bindable/delegate_proxy.rb', line 12

def method_missing(name, *args, &block)
  responses = []
  delegates.each do |delegate|
    responses << delegate.send(name, *args, &block) if delegate.respond_to?(name)
  end

  responses.first
end

Instance Attribute Details

#delegates ⇒ Object

Returns the value of attribute delegates.



6
7
8
# File 'lib/motion_bindable/delegate_proxy.rb', line 6

def delegates
  @delegates
end