U:RDoc::AnyMethod[iI"sum:ETI"Array#sum;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I""Returns the sum of elements. ;TI"?For example, [e1, e2, e3].sum returns init + e1 + e2 + e3.;To:RDoc::Markup::BlankLine o;
; [I"?If a block is given, the block is applied to each element ;TI"before addition.;T@o;
; [I"4If ary is empty, it returns init.;T@o:RDoc::Markup::Verbatim; [I".[].sum #=> 0
;TI"0[].sum(0.0) #=> 0.0
;TI".[1, 2, 3].sum #=> 6
;TI"0[3, 5.5].sum #=> 8.5
;TI"2[2.5, 3.0].sum(0.0) {|e| e * e } #=> 15.25
;TI"6[Object.new].sum #=> TypeError
;T:@format0o;
; [I"HThe (arithmetic) mean value of an array can be obtained as follows.;T@o;; [I"&mean = ary.sum(0.0) / ary.length
;T;
0o;
; [I"8This method can be used for non-numeric objects by ;TI"#explicit init argument.;T@o;; [I"2["a", "b", "c"].sum("") #=> "abc"
;TI"8[[1], [[2]], [3]].sum([]) #=> [1, [2], 3]
;T;
0o;
; [I"HHowever, Array#join and Array#flatten is faster than Array#sum for ;TI"*array of strings and array of arrays.;T@o;; [I"2["a", "b", "c"].join #=> "abc"
;TI"8[[1], [[2]], [3]].flatten(1) #=> [1, [2], 3]
;T;
0o;
; [I"IArray#sum method may not respect method redefinition of "+" methods ;TI"such as Integer#+.;T:
@fileI"array.c;T:0@omit_headings_from_table_of_contents_below0I"_ary.sum(init=0) -> number
ary.sum(init=0) {|e| expr } -> number
;T0[ I"(p1 = v1);T@9FI"
Array;TcRDoc::NormalClass00