This blog is part of our Rails 5 series.
Rails 5 has
deprecated usage of alias_method_chain
in favor of Ruby’s built-in method
What is alias_method_chain and when to use it
A lot of good articles have been written by some very smart people on the topic of “alias_method_chain”. So we will not be attempting to describe it here.
Using Module#prepend to solve the problem
Ruby 2.0 introduced
Module#prepend which allows
us to insert a module before the class
in the class ancestor hierarchy.
Let’s try to solve the same problem using
Now we are back to being nice to our neighbor which should make Ernie happy.
Let’s see what the ancestors chain looks like.
In Ruby 2.1 both
Module#prepend became a public method.
In the above example
we have shown both Ruby 2.0 and
Ruby 2.1 versions.