diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-08-09 18:15:13 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-08-09 18:15:20 +0100 |
commit | 60bed59fbf21fcfe5b9a753181f6d34488055acd (patch) | |
tree | 11229c856c227ea75f0ade25f7a093f6c8993da2 /activesupport | |
parent | 97a5c7a5163b4bf7398939a4ccaf1d04c530ec52 (diff) | |
download | rails-60bed59fbf21fcfe5b9a753181f6d34488055acd.tar.gz rails-60bed59fbf21fcfe5b9a753181f6d34488055acd.tar.bz2 rails-60bed59fbf21fcfe5b9a753181f6d34488055acd.zip |
Remove unnecessary &block from Range#sum and add tests for (num..float).sum
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/core_ext/enumerable.rb | 2 | ||||
-rw-r--r-- | activesupport/test/core_ext/enumerable_test.rb | 1 |
2 files changed, 2 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb index 42686cfbd5..15a303cf04 100644 --- a/activesupport/lib/active_support/core_ext/enumerable.rb +++ b/activesupport/lib/active_support/core_ext/enumerable.rb @@ -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 diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb index 318ba9c0e2..66507d4652 100644 --- a/activesupport/test/core_ext/enumerable_test.rb +++ b/activesupport/test/core_ext/enumerable_test.rb @@ -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 |