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