[前][次][番号順一覧][スレッド一覧]

ruby-changes:42631

From: akr <ko1@a...>
Date: Fri, 22 Apr 2016 19:47:58 +0900 (JST)
Subject: [ruby-changes:42631] akr:r54705 (trunk): [DOC] Arrah#sum with non-numeric objects.

akr	2016-04-22 20:44:34 +0900 (Fri, 22 Apr 2016)

  New Revision: 54705

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54705

  Log:
    [DOC] Arrah#sum with non-numeric objects.

  Modified files:
    trunk/array.c
Index: array.c
===================================================================
--- array.c	(revision 54704)
+++ array.c	(revision 54705)
@@ -5674,7 +5674,19 @@ rb_ary_dig(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/array.c#L5674
  *
  *   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 <i>init</i> 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#+.
  *
  */

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]