---
title: "Rails 5 deprecates alias_method_chain"
description:
  "Rails 5 deprecates alias_method_chain in favor of Ruby's builtin method."
canonical_url: "https://www.bigbinary.com/blog/rails-5-deprecates-alias-method-chain"
markdown_url: "https://www.bigbinary.com/blog/rails-5-deprecates-alias-method-chain.md"
---

# Rails 5 deprecates alias_method_chain

Rails 5 deprecates alias_method_chain in favor of Ruby's builtin method.

- Author: Neeraj Singh
- Published: August 21, 2016
- Categories: Rails 5, Rails

Rails 5 has
[deprecated usage of alias_method_chain](https://github.com/rails/rails/pull/19434)
in favor of Ruby's built-in method `Module#prepend`.

## 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.

[Ernier Miller](https://ernie.io) wrote
[When to use alias_method_chain](https://ernie.io/2011/02/03/when-to-use-alias_method_chain/)
more than five years ago but it is still worth a read.

## 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 `Module#prepend`.

```ruby
module Flanderizer
  def hello
    "#{super}-diddly"
  end
end

class Person
  def hello
    "Hello"
  end
end

# In ruby 2.0
Person.send(:prepend, Flanderizer)

# In ruby 2.1
Person.prepend(Flanderizer)

flanders = Person.new
puts flanders.hello #=> "Hello-diddly"
```

Now we are back to being nice to our neighbor which should make Ernie happy.

Let's see what the ancestors chain looks like.

```ruby
flanders.class.ancestors # => [Flanderizer, Person, Object, Kernel]
```

In Ruby 2.1 both `Module#include` and `Module#prepend` became a public method.
In the above example we have shown both Ruby 2.0 and Ruby 2.1 versions.

## Links

- [Human page](https://www.bigbinary.com/blog/rails-5-deprecates-alias-method-chain)
