Tag: refactoring

Daily Refactor #76: Replace Temp with Query in Invoice#fully_paid?

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 endclass Invoice = self.amount end end After 1 2 3 4 5 class Invoice < ActiveRecord::Base def fully_paid? outstanding <= 0 end endclass Invoice < ActiveRecord::Base def fully_paid? outstanding <= …

Read more

Daily Refactor #74: Extract Method in Invoice

The Refactoring While adding tests to my Redmine Invoice plugin, I found the following nasty bit of logic. Before 1 2 3 4 5 6 7 class Invoice < ActiveRecord::Base   def self.open invoices = self.find(:all) return invoices.select { |invoice| !invoice.fully_paid? && !invoice.late? } end endclass Invoice < ActiveRecord::Base def self.open invoices = self.find(:all) return …

Read more