Class: RubyReduce::Reduce
- Inherits:
-
Object
- Object
- RubyReduce::Reduce
- Defined in:
- lib/ruby_reduce/reduce.rb
Instance Method Summary collapse
- #emit(result) ⇒ Object
-
#initialize(map_result, reduce) ⇒ Reduce
constructor
A new instance of Reduce.
- #reduce ⇒ Object
Constructor Details
#initialize(map_result, reduce) ⇒ Reduce
Returns a new instance of Reduce.
3 4 5 6 7 8 |
# File 'lib/ruby_reduce/reduce.rb', line 3 def initialize(map_result, reduce) @map_result = map_result @reduce = reduce @result = {} end |
Instance Method Details
#emit(result) ⇒ Object
10 11 12 13 |
# File 'lib/ruby_reduce/reduce.rb', line 10 def emit(result) @result[@current_key] ||= [] @result[@current_key] << result end |
#reduce ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ruby_reduce/reduce.rb', line 15 def reduce @map_result.each do |key, values| @current_key = key values.each do |value| instance_exec value, &@reduce end end @result end |