The Refactoring
Since I refactored Invoice#outstanding
yesterday, I can now build on that to refactor Invoice#fully_paid?
.
Before
1 2 3 |
class Invoice = self.amount end end |
After
1 2 3 4 5 |
class Invoice < ActiveRecord::Base def fully_paid? outstanding <= 0 end end |
Review
A nice side benefit of this refactoring is that since #fully_paid?
uses #outstanding
it will also get the performance boost from using the SQL sum.