From 35e2628694de4c788cc0164b0af473613b93c036 Mon Sep 17 00:00:00 2001 From: akr Date: Fri, 22 Apr 2016 11:44:34 +0000 Subject: [DOC] Arrah#sum with non-numeric objects. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54705 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- array.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'array.c') diff --git a/array.c b/array.c index 9f94a6d8dc..5a0d8aa0e5 100644 --- a/array.c +++ b/array.c @@ -5674,7 +5674,19 @@ rb_ary_dig(int argc, VALUE *argv, VALUE self) * * mean = ary.sum(0.0) / ary.length * - * This method may not respect method redefinition of "+" methods + * This method can be used for non-numeric objects by + * explicit init argument. + * + * ["a", "b", "c"].sum("") #=> "abc" + * [[1], [[2]], [3]].sum([]) #=> [1, [2], 3] + * + * However, Array#join and Array#flatten is faster than Array#sum. + * + * ["a", "b", "c"].join #=> "abc" + * [[1], [[2]], [3]].flatten(1) #=> [1, [2], 3] + * + * + * Array#sum method may not respect method redefinition of "+" methods * such as Fixnum#+. * */ -- cgit v1.2.3