Skip to content

Instantly share code, notes, and snippets.

@hsanchez
Forked from barce/classifier_hack.rb
Created February 1, 2012 22:49
Show Gist options
  • Select an option

  • Save hsanchez/1719959 to your computer and use it in GitHub Desktop.

Select an option

Save hsanchez/1719959 to your computer and use it in GitHub Desktop.
monkey patch for Array if using classifier gem
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment