module Redef Redef::VERSION = '0.4.2' def Redef.version() Redef::VERSION end end class Class private def redefined singleton_class = class << self self end hash = Hash.new singleton_class.module_eval{ define_method(:redefined){ hash } } redefined end def redefining &block include( redefined[:Module] ||= Module.new ) m = Module.new(&block) methods = m.instance_methods(false) & instance_methods(false) methods.each do |method| redefined[method] = instance_method method redefined[:Module].module_eval <<-redefintion def #{ method }(*a, &b) self.class.redefined['#{ method }'].bind(self).call(*a, &b) end redefintion remove_method method end include m end alias_method 'redef', 'redefining' end