1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Added documentation for integer range sums (#1593)

This commit is contained in:
Eli Sadoff 2019-12-10 21:25:54 -05:00 committed by Kenta Murata
parent 86e2c013d7
commit 7e9b1609da

4
enum.c
View file

@ -4029,6 +4029,10 @@ int_range_sum(VALUE beg, VALUE end, int excl, VALUE init)
* { 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.
*/