📁 File Manager Pro
v10.0.3 | PHP: 8.1.34
Server: Apache
2026-06-22 08:33:16
📂
/ (Root)
/
opt
/
alt
/
ruby33
/
share
/
ri
/
system
/
Array
📍 /opt/alt/ruby33/share/ri/system/Array
🔄 Refresh
✏️
Editing: sum-i.ri
Read Only
U:RDoc::AnyMethod[iI"sum:ETI"Array#sum;TF:privateo:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I">When no block is given, returns the object equivalent to:;To:RDoc::Markup::BlankLine o:RDoc::Markup::Verbatim; [I"sum = init ;TI",array.each {|element| sum += element } ;TI" sum ;T:@format0o; ; [I"QFor example, <tt>[e1, e2, e3].sum</tt> returns <tt>init + e1 + e2 + e3</tt>.;T@o; ; [I"Examples:;T@o;; [I"a = [0, 1, 2, 3] ;TI"a.sum # => 6 ;TI"a.sum(100) # => 106 ;T; 0o; ; [I"IThe elements need not be numeric, but must be <tt>+</tt>-compatible ;TI"%with each other and with +init+:;T@o;; [I"a = ['abc', 'def', 'ghi'] ;TI"&a.sum('jkl') # => "jklabcdefghi" ;T; 0o; ; [I";When a block is given, it is called with each element ;TI"Xand the block's return value (instead of the element itself) is used as the addend:;T@o;; [I"a = ['zero', 1, :two] ;TI"Gs = a.sum('Coerced and concatenated: ') {|element| element.to_s } ;TI"1s # => "Coerced and concatenated: zero1two" ;T; 0o; ; [I"Notes:;T@o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0; [o; ; [I"?Array#join and Array#flatten may be faster than Array#sum ;TI"5for an \Array of Strings or an \Array of Arrays.;To;;0; [o; ; [I"[Array#sum method may not respect method redefinition of "+" methods such as Integer#+.;T: @fileI"array.c;T:0@omit_headings_from_table_of_contents_below0I"Rarray.sum(init = 0) -> object array.sum(init = 0) {|element| ... } -> object ;T0[ I"(*args);T@@FI" Array;TcRDoc::NormalClass00
💾 Save Changes
❌ Cancel