Sha256: dbf684d338fe97e678ca193ebaaa32026b671e46044677003d3221133ef4a7d9

Contents?: true

Size: 277 Bytes

Versions: 7

Compression:

Stored size: 277 Bytes

Contents

module Enumerable

  # Uses #+ to sum the enumerated elements.
  #
  #   [1,2,3].sum  #=> 6
  #   [3,3,3].sum  #=> 9

  def sum(identity = 0, &block)
    if block_given?
      map(&block).sum
    else
      inject{ |sum, element| sum + element } || identity
    end
  end

end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
facets-2.4.0 lib/facets/enumerable/sum.rb
facets-2.4.1 lib/facets/enumerable/sum.rb
facets-2.4.2 lib/core/facets/enumerable/sum.rb
facets-2.4.3 lib/core/facets/enumerable/sum.rb
facets-2.4.4 lib/core/facets/enumerable/sum.rb
facets-2.4.5 lib/core/facets/enumerable/sum.rb
mack-facets-0.8.2 lib/gems/facets-2.4.5/lib/core/facets/enumerable/sum.rb