Class: Needle::Extras::Multicast::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/needle/extras/multicast.rb

Overview

A proxy that wraps an array of other objects. Whenever a message is received by this proxy, it delegates the call to the objects in the array.

Instance Method Summary collapse

Constructor Details

#initialize(*delegates) ⇒ Target

Creates a new Target object that acts as a proxy for the given list of delegates.



12
13
14
# File 'lib/needle/extras/multicast.rb', line 12

def initialize( *delegates )
  @delegates = delegates
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Forwards the method to each object in the array. It does no checking to ensure that the receiver can understand the message before sending it. This will return an array of the results of calling each of the other messages.



20
21
22
23
24
# File 'lib/needle/extras/multicast.rb', line 20

def method_missing( sym, *args, &block )
  @delegates.inject( [] ) do |a,d|
    a << d.__send__( sym, *args, &block )
  end
end