Class: Functional::Reduce
Instance Attribute Summary
Attributes inherited from Base
#caller, #exe, #next
Instance Method Summary
collapse
Methods inherited from Base
#base_fun, #clean, #to_proc
Constructor Details
#initialize(iv = ::Functional::DEFAULT, *a, &exe) ⇒ Reduce
Returns a new instance of Reduce.
218
219
220
221
222
223
224
225
226
|
# File 'lib/functional.rb', line 218
def initialize iv = ::Functional::DEFAULT, *a, &exe
super *a, &exe
iv = Array.method :new if ::Functional::DEFAULT == iv
@buf = if iv.kind_of?( ::Proc) || iv.kind_of?( ::Method)
Hash.new {|h,k| h[k] = iv.call }
else
{}.tap {|h| h.default = iv }
end
end
|
Instance Method Details
233
234
235
236
|
# File 'lib/functional.rb', line 233
def end
@buf.each &@next.method( :call)
@next.end
end
|
#reduce_fun(k, *a) ⇒ Object
Also known as:
call
228
229
230
|
# File 'lib/functional.rb', line 228
def reduce_fun k, *a
@buf[ k] = @exe.call k, @buf[ k], *a
end
|