Created
June 12, 2012 10:08
-
-
Save andreimaxim/2916714 to your computer and use it in GitHub Desktop.
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" | |
class FooOne | |
def m; 1; end | |
end | |
class FooTwo # classy | |
def m; 1; end | |
end | |
puts FooOne.new.m #=> 1 | |
module Bar | |
def m; 42; end | |
end | |
module Baz | |
def m; 42; end | |
end | |
# Monkey-patching! | |
module Bar | |
extend ActiveSupport::Concern | |
included do | |
alias_method :m_old, :m | |
def m; m_old + 1; end | |
end | |
end | |
class FooOne; include Bar; end | |
puts FooOne.new.m #=> 2 | |
module Baz | |
extend ActiveSupport::Concern | |
included do | |
alias_method :m_oldish, :m | |
def m; m_oldish + 1; end | |
end | |
end | |
class FooTwo; include Bar; include Baz; end | |
puts FooTwo.new.m #=> 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment