Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/reclassifier/core_ext/array.rb

Instance Method Summary collapse

Instance Method Details

#sum_with_identity(identity = 0, &block) ⇒ Object



2
3
4
5
6
7
8
9
10
# File 'lib/reclassifier/core_ext/array.rb', line 2

def sum_with_identity(identity = 0, &block)
  return identity unless size > 0

  if block_given?
    map(&block).sum
  else
    reduce(:+)
  end
end