Skip to content

Instantly share code, notes, and snippets.

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