Module: Polyfill::V2_4::Array
- Included in:
- Polyfill::V2_4
- Defined in:
- lib/polyfill/v2_4/array.rb
Instance Method Summary collapse
Instance Method Details
#concat(*others) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/polyfill/v2_4/array.rb', line 4 def concat(*others) return super if others.length == 1 acc = [].concat(self) others.each do |other| acc.concat(other) end replace(acc) end |
#sum(init = 0) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/polyfill/v2_4/array.rb', line 15 def sum(init = 0) acc = begin init.dup rescue TypeError init end each do |elem| acc += block_given? ? yield(elem) : elem end acc end |