U:RDoc::AnyMethod[iI"reduce:ETI"Enumerable#reduce;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"?Combines all elements of enum by applying a binary ;TI">operation, specified by a block or a symbol that names a ;TI"method or operator.;To:RDoc::Markup::BlankLine o;
; [I"DThe inject and reduce methods are aliases. There ;TI")is no performance benefit to either.;T@o;
; [I"BIf you specify a block, then for each element in enum ;TI"Mthe block is passed an accumulator value (memo) and the element. ;TI"JIf you specify a symbol instead, then each element in the collection ;TI"8will be passed to the named method of memo. ;TI"GIn either case, the result becomes the new value for memo. ;TI"HAt the end of the iteration, the final value of memo is the ;TI"!return value for the method.;T@o;
; [I"OIf you do not explicitly specify an initial value for memo, ;TI"Gthen the first element of collection is used as the initial value ;TI"of memo.;T@o:RDoc::Markup::Verbatim; [I"# Sum some numbers
;TI";(5..10).reduce(:+) #=> 45
;TI"%# Same using a block and inject
;TI";(5..10).inject { |sum, n| sum + n } #=> 45
;TI"# Multiply some numbers
;TI"?(5..10).reduce(1, :*) #=> 151200
;TI"# Same using a block
;TI"?(5..10).inject(1) { |product, n| product * n } #=> 151200
;TI"# find the longest word
;TI";longest = %w{ cat sheep bear }.inject do |memo, word|
;TI"0 memo.length > word.length ? memo : word
;TI" end
;TI"?longest #=> "sheep";T:@format0:
@fileI"enum.c;T:0@omit_headings_from_table_of_contents_below0I"§enum.reduce(initial, sym) -> obj
enum.reduce(sym) -> obj
enum.reduce(initial) { |memo, obj| block } -> obj
enum.reduce { |memo, obj| block } -> obj;T0[ I"(p1 = v1, p2 = v2);T@2FI"Enumerable;TcRDoc::NormalModule00