Skip to content

Instantly share code, notes, and snippets.

@danimal141
Created April 12, 2014 14:11
Show Gist options
  • Save danimal141/10537596 to your computer and use it in GitHub Desktop.
Save danimal141/10537596 to your computer and use it in GitHub Desktop.
How to use alias_method_chain
require 'active_support/core_ext/module/aliasing'
class A
def foo
'foo'
end
end
class B < A
def foo_with_bar
'foobar'
end
alias_method_chain :foo, :bar
end
a = A.new
a.foo # => 'foo'
b = B.new
b.foo # => 'foobar'
b.foo_with_bar # => 'foobar'
b.foo_without_bar # => 'foo'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment