Module: Jinx::Collector
- Defined in:
- lib/jinx/helpers/collector.rb
Overview
The Collector utility implements the Collector.on method to apply a block to a collection transitive closure.
Class Method Summary collapse
-
.on(obj, &block) ⇒ Object
Collects the result of applying the given block to the given obj.
Class Method Details
.on(obj, &block) ⇒ Object
Collects the result of applying the given block to the given obj. If obj is a collection, then collects the result of recursively calling this Collector on the enumerated members. If obj is nil, then returns nil. Otherwise, calls block on obj and returns the result.
16 17 18 |
# File 'lib/jinx/helpers/collector.rb', line 16 def self.on(obj, &block) obj.collection? ? obj.map { |item| on(item, &block) } : yield(obj) unless obj.nil? end |