Ruby 2.0 vs alias_method_chain

One cool feature in Ruby 2.0 is Module#prepend. This allows Modules to override local methods. Previously we used things like alias_method_chain to accomplish the same effect.

Before (Ruby 1.8, Ruby 1.9)

require 'rubygems'
require 'active_support'
require 'active_support/core_ext/module'

module Foo
  def self.included(base)
    base.alias_method_chain :hello, 'mom'
  end

  def hello_with_mom
    hello_without_mom + ' mom'
  end
end

class Bar
  def hello
    'hello'
  end

  include Foo
end

After (Ruby 2.0)

module Foo
  def hello
    super + ' mom'
  end
end

class Bar
  prepend Foo

  def hello
    'hello'
  end
end