Refactoring Ruby: Extract Variable

def total_price
# BAD
price + (price * TAX_PERCENTAGE) - (price * (discount_percentage / 100.0))
end
def total_price
# GOOD
tax = price * TAX_PERCENTAGE
discount = price * (discount_percentage / 100.0)
price + tax - discount
end

--

--

Engineer @convertkit, programming enthusiast, father, and musician

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jon Lunsford

Jon Lunsford

Engineer @convertkit, programming enthusiast, father, and musician