Class: Enumerable::Mapper

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

Overview

An Enumerable::Mapper object works as a proxy for a collection. Any method call on the mapper will be routed to each of the members, and the results will be returned as an array.

Instance Method Summary collapse

Constructor Details

#initialize(collection) ⇒ Mapper

Create a new mapper for a collection.



9
10
11
# File 'lib/enumerable_mapper.rb', line 9

def initialize( collection )
  @collection = collection
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth_id, *args) ⇒ Object

:nodoc:



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

def method_missing( meth_id, *args) #:nodoc:
  @collection.map{ |a| a.send(meth_id, *args) }
end