Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
5 Cards in this Set
- Front
- Back
- 3rd side (hint)
**Extract Method**
You have a code fragment that can be grouped together |
Turn the fragment into a method whose name explains the purpose of the method
https://gist.github.com/vrybas/1982b803d01dc5e591bf |
|
|
**Inline Method**
A method's is just as clear as its name |
Put the method's body into the body of its callers and remove the method
|
#Before:
def get_rating more_than_five_late_deliveries ? 2 : 1 end def more_than_five_late_deliveries @number_of_late_deliveries > 5 end #After: def get_rating @number_of_late_deliveries > 5 ? 2 : 1 end |
|
**Inline Temp**
You have a temp that is assingned to once with a simple expression, and the temp is getting in the way of other reactorings. |
Replace all references to temp with expression
|
#Before:
base_price = an_order.base_price return(base_price > 1000) #After: return (an_order.base_price > 1000) |
|
**Replace Temp with Query**
You are using temporary variable to hold the result of an expression |
Extract the expression into a method. Replace all the references to the temp with the expression. The new method can then be used into other methods.
|
#Before:
def price base_price = @quantity * @item_price if base_price > 1000 discount_factor = 0.95 else discount_factor = 0.98 end base_price * discount_factor end #After: def price base_price * discount_factor end def base_price @quantity * @item_price end def discount_factor base_price > 1000 ? 0.95 : 0.98 end |
|
**Replace Temp with Chain**
You are using a temporary variable to hold the result of an expression |
Change the methods to support chaining, thus removing the need for a temp.
|
#Before:
class Select def options @options ||= [] end def add_option(arg) options << arg end end select = Select.new select.add_option(1999) select.add_option(2000) select.add_option(2001) select.add_option(2002) #After: class Select def options @options ||= [] end def with_option(option) select = self.new select.options << option select end def and(option) options << option self end select = Select.with_option(1999).and(2000).and(2001).and(2002) |