From: dm1 Date: 2005-05-12T18:00:28+09:00 Subject: Re: How to force a method redefinition ? It works nice. Thanks Denis Christoph wrote: > > 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