-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Fernando Perez wrote:
| Hi,
|
| I am wondering if it is possible to create a conditionnal sum.
|
| For instance I would like to do something like this:
|
| @total_amount = @orders.sum { |order| order.amount if order.paid == true
| }
Should be.
Something like this (untested, and unsafe, probably not even correct):
def conditional_sum order, condition
~ order.each do |o|
~ sum = sum + o unless o.paid?
~ end
~ return sum
end
I made the idea explicit, so that you should at least get the idea.
- --
Phillip Gawlowski
Twitter: twitter.com/cynicalryan
Blog:
http://justarubyist.blogspot.com
You! What PLANET is this!
~ -- McCoy, "The City on the Edge of Forever", stardate 3134.0
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla -
http://enigmail.mozdev.org
iEYEARECAAYFAkgsZ9UACgkQbtAgaoJTgL8L2gCeLZyAQcn6+o+4McD7qQLJlL1o
qEUAn0JrnuPs7XVBNUYAEuCd6gUIsjBO
=k8YY
-----END PGP SIGNATURE-----