Repository URL to install this package:
Version:
2.2.2-1 ▾
|
U:RDoc::AnyMethod[iI"reduce:ETI"Enumerable#reduce;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"?Combines all elements of <i>enum</i> 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"BIf you specify a block, then for each element in <i>enum</i> ;TI"Mthe block is passed an accumulator value (<i>memo</i>) 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 <i>memo</i>. ;TI"GIn either case, the result becomes the new value for <i>memo</i>. ;TI"HAt the end of the iteration, the final value of <i>memo</i> is the ;TI"!return value for the method.;T@o; ; [I"OIf you do not explicitly specify an <i>initial</i> value for <i>memo</i>, ;TI"Gthen the first element of collection is used as the initial value ;TI"of <i>memo</i>.;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@.FI"Enumerable;TcRDoc::NormalModule00