lib/core/facets/enumerable/sum.rb in facets-2.9.2 vs lib/core/facets/enumerable/sum.rb in facets-2.9.3

- old
+ new

@@ -3,12 +3,14 @@ # Uses #+ to sum the enumerated elements. # # [1,2,3].sum #=> 6 # [3,3,3].sum #=> 9 # - def sum(identity = 0, &block) + # @author Dawid Marcin Grzesiak (bug fix) + + def sum(identity=0, &block) if block_given? - map(&block).sum + map(&block).sum(identity) else inject{ |sum, element| sum + element } || identity end end