lib/polyfill/v2_4/array.rb in polyfill-0.7.0 vs lib/polyfill/v2_4/array.rb in polyfill-0.8.0

- old
+ new

@@ -1,8 +1,12 @@ +require_relative 'numeric' + module Polyfill module V2_4 module Array + using Polyfill(Numeric: %w[#dup]) + def concat(*others) return super if others.length == 1 acc = [].concat(self) others.each do |other| @@ -11,17 +15,13 @@ replace(acc) end def sum(init = 0) - acc = - begin - init.dup - rescue TypeError - init - end + acc = init.dup - each do |elem| + for i in 0..(size - 1) # rubocop:disable Style/For + elem = self[i] acc += block_given? ? yield(elem) : elem end acc end