From: Christoph Date: 2005-05-12T10:34:48+09:00 Subject: Re: How to force a method redefinition ? Robert Klemme schrieb: > > There are several ways. You can for example fetch methods from a > module with "B.instance_method :xx" and then bind it to an instance. > What do you need that for? I guess that would work out --- module FRedef def self.extended(mod) mod.instance_eval do @instance_methods = Hash.new instance_methods(false).each do |sym| @instance_methods[sym] = instance_method(sym) remove_method(sym) end end end private def append_features(mod) @instance_methods.each do |sym,mth| mod.__send__(:define_method,sym,mth) end super end end module B def xx ; puts "in B" ; end extend FRedef end module C def xx ; puts "in C"; end extend FRedef end module D def xx ; puts "in D"; end extend FRedef end include B ; xx include C ; xx include D ; xx include B ; xx include C ; xx --- Note with the -w option you'll get redefinition warnings - check out singleton.rb on how to avoid this. /Christoph