class Mapper::Some

“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.

Public Class Methods

new(objects, &block) click to toggle source

Constructor.

# File lib/mapper/some.rb, line 35
def initialize(objects, &block)
    @objects = objects
    @condition = block
end

Public Instance Methods

method_missing(name, *args, &block) click to toggle source

Handles calls. (Performs mapping.)

Returns result of first one for which is condition true, or result of last object call.

# 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