Skip to content

Instantly share code, notes, and snippets.

@huacnlee
Created October 22, 2015 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huacnlee/4969bee62f02be167949 to your computer and use it in GitHub Desktop.
Save huacnlee/4969bee62f02be167949 to your computer and use it in GitHub Desktop.
A simple case for use ActiveSupport alias_method_chain
require 'active_support/all'
class Foo
def foo
bar
puts "foo"
end
private
def bar
puts "bar"
end
end
module Extend
extend ActiveSupport::Concern
included do
alias_method_chain :foo, :ext
alias_method_chain :bar, :ext
end
def foo_with_ext
bar
puts "foo ext"
end
def bar_with_ext
puts "bar ext"
end
end
foo = Foo.new
foo.foo
puts "==============="
Foo.send(:include, Extend)
foo1 = Foo.new
foo.foo
bar
foo
===============
bar ext
foo ext
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment