Refactoring: Refactorings/Remove Unused Default Parameter
Jump to navigation
Jump to search
A parameter has a default value, but all method calls provide a value for the parameter; so we need to remove the default value.
Mechanics
- Remove the default parameter in the method signature
- Test
- Remove any code within the method that checks for the default value
- Test
Example
Before
def product_count_items(search_criteria=nil)
criteria = search criteria | @search_criteria
ProductCountItem.find_all_by_criteria(criteria)
end
After
def product_count_items(search_criteria)
ProductCountItem.find_all_by_criteria(search_criteria)
end