mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Remove unnecessary &block from Range#sum and add tests for (num..float).sum
This commit is contained in:
parent
97a5c7a516
commit
60bed59fbf
2 changed files with 2 additions and 1 deletions
|
@ -115,7 +115,7 @@ end
|
|||
class Range #:nodoc:
|
||||
# Optimize range sum to use arithmetic progression if a block is not given and
|
||||
# we have a range of numeric values.
|
||||
def sum(identity=0, &block)
|
||||
def sum(identity = 0)
|
||||
return super if block_given? || !(first.instance_of?(Integer) && last.instance_of?(Integer))
|
||||
actual_last = exclude_end? ? (last - 1) : last
|
||||
(actual_last - first + 1) * (actual_last + first) / 2
|
||||
|
|
|
@ -66,6 +66,7 @@ class EnumerableTests < Test::Unit::TestCase
|
|||
assert_equal 10, (1..4).sum
|
||||
assert_equal 6, (1...4).sum
|
||||
assert_equal 'abc', ('a'..'c').sum
|
||||
assert_raises(NoMethodError) { 1..2.5.sum }
|
||||
end
|
||||
|
||||
def test_each_with_object
|
||||
|
|
Loading…
Reference in a new issue