MultiplexingDelegator
by Justin Knowlden
http://glomp.rubyforge.org/multiplexing_delegator

== DESCRIPTION:

MultiplexingDelegator is used to define a delegator method that
multiplexes calls from one method across many methods for an instance of an
object. The class method is usable for any type of Object, but was intended for
use within an ActiveRecord object.

The delegator works by calling the same method across multiple methods or
accessors for a given object instance and aggregating the results.

== FEATURES/PROBLEMS:

* Adds a multiplex class method to all Objects

== SYNOPSIS:

Example
class Foo
attr_accessor :baz, :bum
multiplex :bar, :across => [:baz, :bum]
end

foo = Foo.new
foo.baz = 1
foo.bum = 'boo'
foo.bar.map => [1, 'boo']
foo.bar.each {|item| puts "Yo yo #{item}"}
=> Yo yo 1
=> Yo yo boo

You can also proxy method calls to each of the delegated items and results
will be aggregated. This was the actual impetus behind writing this little gem.

Example
class Goo
attr_accessor :car
def initialize(car) @car = car; end
end

foo = Foo.new
foo.baz = Goo.new('hello')
foo.bum = Goo.new('world')
foo.bar.car => ['hello, 'world']

A feature of multiplex that you may not expect is that it will flatten
arrays to one-level deep so as to simulate a single stream of results. For
instance, using Foo from above:

foo = Foo.new
foo.baz = 'hello world'
foo.bum = ['how', 'are', 'you]
foo.bar.map => ['hello world', 'how', 'are', 'you']

However, multiplex will not flatten more than one level deep. For example:

foo = Foo.new
foo.baz = [['hello', 'world']]
foo.bum = [['how', 'are', 'you]]
foo.bar.map => [['hello', 'world'], ['how', 'are', 'you']]

== REQUIREMENTS:

Ruby 1.8.6 and above

== INSTALL:

sudo gem install multiplexing_delegator

== LICENSE:

(The MIT License)

Copyright (c) 2008 Justin Knowlden

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.