Sha256: 4942299cb1f71ce6e701d567a2c6a664e6ec443b932e1b1ead2318e94021f366

Contents?: true

Size: 280 Bytes

Versions: 16

Compression:

Stored size: 280 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

16 entries across 15 versions & 1 rubygems

Version Path
facets-2.9.2 src/core/facets/enumerable/sum.rb
facets-2.9.2 lib/core/facets/enumerable/sum.rb
facets-2.9.1 lib/core/facets/enumerable/sum.rb
facets-2.9.0 lib/core/facets/enumerable/sum.rb
facets-2.9.0.pre.2 lib/core/facets/enumerable/sum.rb
facets-2.9.0.pre.1 lib/core/facets/enumerable/sum.rb
facets-2.8.4 lib/core/facets/enumerable/sum.rb
facets-2.8.3 lib/core/facets/enumerable/sum.rb
facets-2.8.2 lib/core/facets/enumerable/sum.rb
facets-2.8.1 lib/core/facets/enumerable/sum.rb
facets-2.8.0 lib/core/facets/enumerable/sum.rb
facets-2.7.0 lib/core/facets/enumerable/sum.rb
facets-2.6.0 lib/core/facets/enumerable/sum.rb
facets-2.5.1 lib/core/facets/enumerable/sum.rb
facets-2.5.0 lib/core/facets/enumerable/sum.rb
facets-2.5.2 lib/core/facets/enumerable/sum.rb