trackoid
trackoid copied to clipboard
Ruby 2.0 regression on sum
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.
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