diff options
author | Marc-Andre Lafortune <github@marc-andre.ca> | 2009-04-14 01:12:55 -0400 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-08-08 17:51:09 -0700 |
commit | 29096268ccce2b13e1490c8b673ffe0b498555fc (patch) | |
tree | 3fdb677bca442e2967f180db42003032c7aa1912 /activesupport/lib | |
parent | 3b3798506b403911665c3c24fd055b75d6f6a44f (diff) | |
download | rails-29096268ccce2b13e1490c8b673ffe0b498555fc.tar.gz rails-29096268ccce2b13e1490c8b673ffe0b498555fc.tar.bz2 rails-29096268ccce2b13e1490c8b673ffe0b498555fc.zip |
Enumerable#sum now works will all enumerables, even if they don't respond to :size
[#2489 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/enumerable.rb | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb index 434a32b29b..e89b7e392e 100644 --- a/activesupport/lib/active_support/core_ext/enumerable.rb +++ b/activesupport/lib/active_support/core_ext/enumerable.rb @@ -55,12 +55,10 @@ module Enumerable # [].sum(Payment.new(0)) { |i| i.amount } # => Payment.new(0) # def sum(identity = 0, &block) - return identity unless size > 0 - if block_given? - map(&block).sum + map(&block).sum(identity) else - inject { |sum, element| sum + element } + inject { |sum, element| sum + element } || identity end end |