Module: Polyfill::V2_4::Array
- Defined in:
- lib/polyfill/v2_4/array.rb
Instance Method Summary collapse
Instance Method Details
#concat(*others) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/polyfill/v2_4/array.rb', line 8 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
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/polyfill/v2_4/array.rb', line 19 def sum(init = 0) acc = init.dup for i in 0..(size - 1) # rubocop:disable Style/For elem = self[i] acc += block_given? ? yield(elem) : elem end acc end |