Join GitHub today
Refining Array#sum monkey-patch using Refinements #27363
Here's an alternative implementation of
I'd like to ask the core members' opinion about this approach, since AFAIK we've never used Refinements in our code base before.
Looks good to me
I think Refinements are best tool to solve this problem :)
Jan 3, 2017
a late comment ... why does this need to be hidden that much esp. in an open language such as Ruby?
maybe there's a reason why its the most unused feature (besides doing terrible on JRuby) - just guessing
UPD Sorry, misunderstood the original purpose of PR.
module ActiveSupport::NumericSum def sum(init = nil, *, &block) #:nodoc: init ||= 0 if !init && first.is_a?(Numeric) super end end Array.prepend(ActiveSupport::NumericSum)