Skip to content

lujanfernaud/explaining-variable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Upcase Refactoring Trail

Explaining Variable

Refactoring exercise using the Extract Variable refactoring for the Upcase Refactoring Trail.

Extract Variable

Put the result of the expression, or parts of the expression, in a temporary variable with a name that explains the purpose. -- Martin Fowler

Before

def total
  amount + (amount * TAX) - (amount * (discount_percentage / 100.0)) + (amount * (tip_percentage / 100.0))
end

After

def total
  tax      = amount * TAX
  discount = amount * (discount_percentage / 100.0)
  tip      = amount * (tip_percentage / 100.0)

  amount + tax - discount + tip
end

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •