Skip to content

Commit

Permalink
Don't define Array#sum if already defined. Fixes #58
Browse files Browse the repository at this point in the history
Recent versions of ActiveSupport and Ruby 2.4.1 have added a #sum method
to the Enumerable class. Their implementation also accepts a block,
which the version included with StatSample does not.

This change tests to see if Array#sum is already defined before
patching.

This fixes issue #58 #58
  • Loading branch information
rdlugosz committed Aug 11, 2017
1 parent 6c6086c commit c605013
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/statsample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ def include_aliasing(m, suffix = 'ruby')
end

class Array
def sum
inject(:+)
unless method_defined?(:sum)
def sum
inject(:+)
end
end

def mean
Expand Down

0 comments on commit c605013

Please sign in to comment.