From c605013d9a4ad7988ba517f576ed64bbffedc28e Mon Sep 17 00:00:00 2001 From: Ryan Dlugosz Date: Fri, 11 Aug 2017 13:34:23 -0400 Subject: [PATCH] Don't define Array#sum if already defined. Fixes #58 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 https://github.com/SciRuby/statsample/issues/58 --- lib/statsample.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/statsample.rb b/lib/statsample.rb index ce5cc8b..1352a54 100644 --- a/lib/statsample.rb +++ b/lib/statsample.rb @@ -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