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

ruby-changes:59188

From: Eli <ko1@a...>
Date: Wed, 11 Dec 2019 18:31:37 +0900 (JST)
Subject: [ruby-changes:59188] 7e9b1609da (master): Added documentation for integer range sums (#1593)

https://git.ruby-lang.org/ruby.git/commit/?id=7e9b1609da

From 7e9b1609dae0998a4418179f40dc488842c56e5d Mon Sep 17 00:00:00 2001
From: Eli Sadoff <9064062+snood1205@u...>
Date: Tue, 10 Dec 2019 21:25:54 -0500
Subject: Added documentation for integer range sums (#1593)


diff --git a/enum.c b/enum.c
index 89148e9..db5f4d3 100644
--- a/enum.c
+++ b/enum.c
@@ -4029,6 +4029,10 @@ int_range_sum(VALUE beg, VALUE end, int excl, VALUE init) https://github.com/ruby/ruby/blob/trunk/enum.c#L4029
  *   { 1 => 10, 2 => 20 }.sum([])                   #=> [1, 10, 2, 20]
  *   "a\nb\nc".each_line.lazy.map(&:chomp).sum("")  #=> "abc"
  *
+ * If the method is applied to an Integer range without a block,
+ * the sum is not done by iteration, but instead using Gauss's summation
+ * formula.
+ *
  * Enumerable#sum method may not respect method redefinition of "+"
  * methods such as Integer#+, or "each" methods such as Range#each.
  */
-- 
cgit v0.10.2


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

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