Refactoring: Refactorings/Inline Method
Jump to navigation
Jump to search
Method's content is just as clear (and as short) as its name. Useful before Replace Method with Method Object
Mechanics
- Check that method is not polymorphic (overridden in subclass)
- Note: Don't inline if subclasses override the method; they cannot override a method that isn't there.
- Find all calls to the method
- Replace each call with the method body.
- Test
- Remove method definition
Example
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