Class: Mapper::Some
- Inherits:
-
Object
- Object
- Mapper::Some
- Defined in:
- lib/mapper/some.rb
Overview
“One after one” reductor.
Passes call with given arguments to each object from oldest to newest in aggregator if the output of given block isn’t true
.
Instance Method Summary collapse
-
#initialize(objects, &block) ⇒ Some
constructor
Constructor.
-
#method_missing(name, *args, &block) ⇒ Object
Handles calls.
Constructor Details
#initialize(objects, &block) ⇒ Some
Constructor.
35 36 37 38 |
# File 'lib/mapper/some.rb', line 35 def initialize(objects, &block) @objects = objects @condition = block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Handles calls. (Performs mapping.)
Returns result of first one for which is condition true
, or result of last object call.
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mapper/some.rb', line 47 def method_missing(name, *args, &block) result = nil @objects.each do |obj| result = obj.send(name, *args, &block) if @condition.call(result) return result end end return result end |