Skip to content

Instantly share code, notes, and snippets.

@dolzenko
Created October 19, 2009 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dolzenko/213439 to your computer and use it in GitHub Desktop.
Save dolzenko/213439 to your computer and use it in GitHub Desktop.
sum_with_enumerable_fallback
ActiveRecord::Associations::AssociationCollection.class_eval do
def sum_with_enumerable_fallback(*args, &block)
if args.empty? && block
to_a.sum(&block)
else
sum_without_enumerable_fallback(*args)
end
end
alias_method_chain :sum, :enumerable_fallback
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment