Skip to content

Instantly share code, notes, and snippets.

@clyfe
Created June 12, 2012 10:19
Show Gist options
  • Save clyfe/2916753 to your computer and use it in GitHub Desktop.
Save clyfe/2916753 to your computer and use it in GitHub Desktop.
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