Skip to content

lujanfernaud/replace-variable-with-query

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Upcase Refactoring Trail

Replace Variable with Query

Refactoring exercise using the Replace Temp with Query refactoring for the Upcase Refactoring Trail.

Replace Temp with Query

Extract the expression into a method. Replace all references to the temp with the expression. The new method can then be used in other methods. -- Martin Fowler

Before

class Tipper
  ...

  def total
    tax_amount      = amount * TAX
    discount_amount = amount * (discount_percentage / 100.0)
    tip_amount      = amount * (tip_percentage / 100.0)

    amount + tax_amount - discount_amount + tip_amount
  end
end

After

class Tipper
  ...

  def total
    amount + tax_amount - discount_amount + tip_amount
  end

  private

  def tax_amount
    amount * TAX
  end

  def discount_amount
    amount * (discount_percentage / 100.0)
  end

  def tip_amount
    amount * (tip_percentage / 100.0)
  end
end

Additional Resources

About

Replace Temp with Query refactoring

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published