I have the following line of code which very simply decrements a Shareholders number of stocks (integer in the DB) when they sell them to someone else. This works well and as expected.
@selling_shareholder.update_attribute(:number_of_stocks, @selling_shareholder.number_of_stocks -= @transaction.number_of_stocks)
Very simply what I'd like to do is have the decrement function stop when the number_of_stocks
hits 0 i.e. having a negative number should not be possible.
I guess I could use a simple unless @selling_shareholder.number_of_stocks > 0
at the end of the line, but I'm wondering if that will actually work without using a loop?