Skip to content

Instantly share code, notes, and snippets.

@massive
Created April 25, 2011 11:12
Show Gist options
  • Save massive/940375 to your computer and use it in GitHub Desktop.
Save massive/940375 to your computer and use it in GitHub Desktop.
module Test
class One
def instance
puts "instance"
end
def self.class_meth
puts "class"
end
end
end
module Override
module Test
def self.included(base)
base.send :extend, ClassMethods
base.send :include, InstanceMethods
base.class_eval do
alias_method :old_instance, :instance
alias_method :instance, :new_instance
class << self
alias_method :old_class_meth, :class_meth
alias_method :class_meth, :new_class_meth
end
end
end
module InstanceMethods
def new_instance
puts "overridden instance"
end
end
module ClassMethods
def new_class_meth
puts "overridden class_meth"
end
end
end
end
Test::One.send(:include, Override::Test)
Test::One.new.instance # => "overridden instance"
Test::One.class_meth # => "overridden class_meth"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment