Method: Array#sum
- Defined in:
- lib/active_support/core_ext/enumerable.rb
#sum(init = nil, &block) ⇒ Object
Array#sum was added in Ruby 2.4 but it only works with Numeric elements.
241 242 243 244 245 246 247 248 |
# File 'lib/active_support/core_ext/enumerable.rb', line 241 def sum(init = nil, &block) if init.is_a?(Numeric) || first.is_a?(Numeric) init ||= 0 orig_sum(init, &block) else super end end |