Server IP : 111.118.215.189 / Your IP : 216.73.216.153 Web Server : Apache System : Linux md-in-83.webhostbox.net 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64 User : a1673wkz ( 2475) PHP Version : 8.2.25 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /proc/thread-self/root/opt/cpanel/ea-ruby24/root/usr/share/ri/system/Enumerable/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
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"DThe <i>inject</i> and <i>reduce</i> methods are aliases. There ;TI")is no performance benefit to either.;T@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@2FI"Enumerable;TcRDoc::NormalModule00