Created
October 22, 2015 03:55
-
-
Save huacnlee/4969bee62f02be167949 to your computer and use it in GitHub Desktop.
A simple case for use ActiveSupport alias_method_chain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bar | |
foo | |
=============== | |
bar ext | |
foo ext |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment