如同你一样,它应当把方法参数附在你重新使用的方法的标子上,并将方法作为实例变量加以利用。
简单令人满意:
- Introduce new instance variables, one per method parameter.
- Introduce new accessors for the instance variables.
- Refactor the method to use the instance variables if the parameters are not supplied.
- Refactor the calling code to set the instance variables through the accessors, at some point prior to the method call.
- Refactor the calling code to pass no parameters in the method call.
As an example, refactor calling code like this:
widget = Widget.new
assembly_method = widget.method(:assemble)
# Time passes...
assembly_method.call(:electric, :smooth)
to work like this:
widget = Widget.new
widget.frombulator = :electric
widget.jazzifier = :smooth
assembly_method = widget.method(:assemble)
# Time passes...
assembly_method.call
它不带有性别色彩,而是会形成表达其意图的法典,奇怪的是,它会处理真正的问题,即你模式中缺少的东西。