Created
June 12, 2012 10:19
-
-
Save clyfe/2916753 to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
module M1 | |
def m; 1 end | |
end | |
module M2 | |
def m; super + 1 end | |
end | |
# monkey patch M1 and M2 to inc m + 1 | |
module P | |
extend ActiveSupport::Concern | |
included do | |
alias_method_chain :m, :patch | |
end | |
def m_with_patch | |
m_without_patch + 1 | |
end | |
end | |
M1.send :include, P | |
M2.send :include, P | |
# end mp | |
class C1 | |
include M1 | |
end | |
class C2 | |
include M1 | |
include M2 | |
end | |
puts C1.new.m # must be > 1 | |
puts C2.new.m # must be > 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment