Encadenamiento de Alias

As we’ve seen, metaprogramming in Ruby often involves the dynamic definition of methods.

Just as common is the dynamic modification of methods.

Methods are modified with a technique we’ll call alias chaining.

It works like this:

  1. First, create an alias for the method to be modified. This alias provides a name for the unmodified version of the method.
  2. Next, define a new version of the method. This new version should call the unmodified version through the alias, but it can add whatever functionality is needed before and after it does that.
Note that these steps can be applied repeatedly (as long as a different alias is used each time), creating a chain of methods and aliases.

Casiano Rodriguez León 2015-06-18