Closed masnick closed 3 months ago
I have the same problem. I'm trying to fix this, so if I succed, I'll give you to know.
Unpack the gem in your vendor directory (gem unpack classifier) and rewrite the sum method in lib/classifier/extensions/vector.rb like this:
def sum(identity = 0, &block)
return identity unless size > 0
if block_given?
map(&block).sum
else
a = inject( nil ) { |sum,x| sum ? sum+x : x }
#Hack to remove the to_f error
a.is_a?(Array) ? a : a.to_f
end
end
That worked! Thanks! Any chance of cardmagic rolling this into the main branch?
Running into the same problem. Using rails 3 I can't unpack the gem as I was used to doing in rails 2. When I fork Classifier here on github I end up with a slew of other errors on bundle install.
I'd love to hear if cardmagic might roll a fix for this issue into the main branch. Any chance?
Add a monkey patch to config/initializers/classifier_hack.rb if you are using rails3
class Array
def sum(identity = 0, &block)
return identity unless size > 0
if block_given?
map(&block).sum
else
a = inject( nil ) { |sum,x| sum ? sum+x : x }
# Hack to remove the to_f error
a.is_a?(Array) ? a : a.to_f
end
end
end
Fixed in version 1.4.0 and above
Unfortunately the problem I was having before still isn't solved...here's the error I'm getting now:
/Library/Ruby/Gems/1.8/gems/classifier-1.3.3/lib/classifier/extensions/vector.rb:16:in
sum': undefined methodto_f' for []:Array (NoMethodError)