-
-
Save bnadlerjr/607873 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fork this and add your example | |
# = Extract Superclass | |
# | |
# == Before Refactor | |
class Department | |
attr_reader :total_annual_cost, :name, :head_count | |
end | |
class Employee | |
attr_reader :annual_cost, :name, :id | |
end | |
# == After "Extract Superclass" Refactoring | |
class Party | |
attr_reader :annual_cost, :name | |
end | |
class Employee < Party | |
attr_reader :id | |
end | |
class Department < Party | |
attr_reader :head_count | |
end | |
# == After "Extract Superclass" (using module) | |
module Party | |
attr_reader :annual_cost, :name | |
end | |
class Employee | |
include Party | |
attr_reader :id | |
end | |
class Department | |
include Party | |
attr_reader :head_count | |
end | |
# = Replace Nested Conditional with Guard Clauses | |
# | |
# == Before Refactoring | |
def get_payment_amount | |
if dead? | |
result = dead_amount | |
elsif separated? | |
result separated_amount | |
elsif retired? | |
result retired_amount | |
else | |
result = normal_pay_amount | |
end | |
result | |
end | |
# == After Refactoring | |
def get_payment_amount | |
return dead_amount if dead? | |
return separted_amount if separated? | |
return retired_amount if retired? | |
normal_pay_amount | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment