Skip to content

Instantly share code, notes, and snippets.

@brandon-beacher
Created November 13, 2011 21:38
Show Gist options
  • Save brandon-beacher/1362760 to your computer and use it in GitHub Desktop.
Save brandon-beacher/1362760 to your computer and use it in GitHub Desktop.
def charity_donations_total_amount
charity_donations.reduce(0) do |sum, charity_donation|
sum + charity_donation.total_amount
end
end
# versus
def charity_donations_total_amount
sum = 0
charity_donations.each do |charity_donation|
sum += charity_donation.total_amount
end
sum
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment