Return nil when break the injection block earilier

Viewed 2428

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
1 Answers
Related