Module: Enumerable

Included in:
NMatrix
Defined in:
lib/nmatrix/jruby/enumerable.rb

Overview

Instance Method Summary collapse

Instance Method Details

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

Standard in rails… See official documentation Modified from rails 2.3 to not rely on size



5
6
7
8
9
10
11
# File 'lib/nmatrix/jruby/enumerable.rb', line 5

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