Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#sum method breaks with Ruby 2.4 #44

Open
moveson opened this issue Dec 27, 2017 · 6 comments
Open

#sum method breaks with Ruby 2.4 #44

moveson opened this issue Dec 27, 2017 · 6 comments

Comments

@moveson
Copy link

moveson commented Dec 27, 2017

Rails does some gymnastics to use the Enumerable#sum method built into Ruby 2.4+, and it falls back to the ActiveSupport Enumerable#sum method to handle situations in which the Ruby method doesn't handle it, such as an Array of Strings. Unfortunately, DescriptiveStatistics' #sum method gets in the way and breaks things when the Array is empty.

Using Ruby 2.4.2 and Rails 5.1.4 with descriptive_statistics 2.5.1:

>> [].sum
#> NoMethodError: undefined method `each' for nil:NilClass

See this post on StackOverflow for details.

@mhluska
Copy link

mhluska commented Jun 17, 2018

@moveson how did you solve this?

@moveson
Copy link
Author

moveson commented Jun 17, 2018

@mhluska I got no response from this issue, so I was forced to remove this gem.

@nsoseka
Copy link

nsoseka commented Sep 11, 2018

If you read the docs carefully you will notice there is a way of working with the gem without using the monkey patch approach which is what will solve your problem. Import refinements and include descriptive_statistics on the objects you want to use it on

@arushs
Copy link

arushs commented Sep 26, 2018

@thirtysixthspan This doesn't look like it's been solved. Is there anything blocking from pushing a PR and merging it? Is it blocked by supporting Ruby 2.4?

@curious725
Copy link

@moveson You didn't used gem in the right way.
I have prototyped this situation
One option that you have - add gem descriptive_statistics in your Gemfile:
gem 'descriptive_statistics', require: false
and then use safe version

require 'descriptive_statistics/safe'

data = []
data.extend(DescriptiveStatistics)
data.sum

In that way everything works.

@mzaharie
Copy link

With rake tasks I had to do the import inside the task block like:

  task my_task: :environment do
    require 'word-to-markdown' # avoid it being auto loaded in other tasks

This way I can safely work with rails 7 models in other tasks.

Note, word-to-markdown uses descriptive_statistics

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants