I want to sum up the orders amount.
but if order.upgrade != nil
I will end the block instantly.
But I got the nil
value.
That wasn't my expectation.
How to achieve my goal?
Thanks
points = orders.inject(0) do |sum, order |
break if order.upgrade != nil
sum += order.actual_amount if order.actual_amount
end
points = orders.inject(0) do |sum, order |
break sum unless order.upgrade.nil?
sum += order.actual_amount || 0
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With