Module: ArrayExtensions
- Defined in:
- lib/array_extensions.rb
Instance Method Summary collapse
-
#sum(identity = 0, &block) ⇒ Object
from Active Support library.
Instance Method Details
#sum(identity = 0, &block) ⇒ Object
from Active Support library
4 5 6 7 8 9 10 11 12 |
# File 'lib/array_extensions.rb', line 4 def sum(identity = 0, &block) return identity unless size > 0 if block_given? map(&block).sum else inject { |sum, element| sum + element } end end |