In lib/statsample.rb, the core Ruby Array class is monkey-patched to change the behavior of the sum method:
Active Support (included by Rails) already defines behavior for #sum, which has slightly different behavior and can accept a block for evaluation: https://github.com/rails/rails/blob/3d716b9e66e334c113c98fb3fc4bcf8a945b93a1/activesupport/lib/active_support/core_ext/enumerable.rb#L2-L27
Similarly, the Ruby core library added the #sum method to the Enumerable class in Ruby 2.4:
As such, for example, the following code works both with Active Support and/or Ruby 2.4:
> x = ['foo', 'bar']
#=> ["foo", "bar"]
> x.sum(&:bytesize)
#=> 6
But fails when the statsample 2.0 library is included in the project's Gemfile:
> x = ['foo', 'bar']
#=> ["foo", "bar"]
> x.sum(&:bytesize)
#=> "foobar"
Can this monkey-patching be removed and the suming functionality be done directly only where needed? This is preventing me from using statsample, unfortunately.
In
lib/statsample.rb, the core RubyArrayclass is monkey-patched to change the behavior of thesummethod:statsample/lib/statsample.rb
Lines 57 to 59 in 0f283e2
Active Support (included by Rails) already defines behavior for
#sum, which has slightly different behavior and can accept a block for evaluation: https://github.com/rails/rails/blob/3d716b9e66e334c113c98fb3fc4bcf8a945b93a1/activesupport/lib/active_support/core_ext/enumerable.rb#L2-L27Similarly, the Ruby core library added the
#summethod to the Enumerable class in Ruby 2.4:As such, for example, the following code works both with Active Support and/or Ruby 2.4:
But fails when the
statsample2.0 library is included in the project's Gemfile:Can this monkey-patching be removed and the
suming functionality be done directly only where needed? This is preventing me from usingstatsample, unfortunately.