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

Ruby 2.0 regression on sum #26

Open
JamesHarrison opened this issue Mar 26, 2013 · 1 comment
Open

Ruby 2.0 regression on sum #26

JamesHarrison opened this issue Mar 26, 2013 · 1 comment

Comments

@JamesHarrison
Copy link

Not got time to dig into this one but after an update to Ruby 2.0.0-p0, calls like:

@image.views.last_days(7).sum

Throws Mongoid::Tracking::ReaderExtender can't be coerced into Fixnum.

@image.views.last_days(7).map{|v|v.to_f}.sum.to_i

Works as a hacky workaround - #to_i in the map function or #total both fail, to_f seems to work.

@carlson
Copy link
Contributor

carlson commented Apr 12, 2013

I swapped "other + @ToTal" in the first argument of the initializer and it resolved the issue for me.

  def +(other)
    return @total + other unless other.is_a?(ReaderExtender)
    self.class.new(other + @total, @hours.zip(other.hourly).map!(&:sum))
  end

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

2 participants