Handling delegation
Delegation refers to taking the arguments that were passed to one method and passing those arguments to a different method. In Ruby, it's common to use delegation to wrap calls to other methods in order to add behavior around the method call. Handling delegation incorrectly can make debugging and refactoring more difficult, so it useful to learn how best to implement it.
Let's say you have a public method you want to rename:
def foo(*args, **kwargs, &block) Â Â [args, kwargs, block] end
Let's say you just rename the method, as follows:
def bar(*args, **kwargs, &block) Â Â [args, kwargs, block] end
Here, you break backward compatibility for users calling foo
.
The best way to handle this is to re-add the same method you are renaming, have it issue a deprecation warning, and then forward all arguments to the renamed method:
def foo(*args, **kwargs, &block) Â Â warn("foo is being renamed to...