From: "David A. Black" Date: 2005-03-09T23:06:56+09:00 Subject: Re: Module#dup and Module.remove_method question Hi -- On Wed, 9 Mar 2005, Renald Buter wrote: > Hello, > > I have a question about Module#dup and Module.remove_method. > > Say I have the following: > > > module A > > def self.foo; puts "A::foo; end > > end > > > B = A.dup > > B.foo > "A::foo" > => nil > > But now I want to remove foo from A's duplicate: > > > class < NameError: method `foo' not defined in Module > from (irb):37:in `remove_method' > from (irb):37 > > Ah? Well OK, let's remove it from A then. > > > class < => # > > Let's test it: > > > A.foo > NoMethodError: undefined method `foo' for A:Module > from (irb):40 > irb(main):041:0> > > That works. BUT: > > > B.foo > "A::foo" > => nil > > This, I do not understand: where does B.foo live, now and why can't I > remove it? B.foo lives in A (the methods don't get dup'd when the class object is dup'd), and to remove it from B you can use undef_method. remove_method will only operate on the module where the method was defined, whereas undef_method will take it out of the search path of any module that could see it before. David -- David A. Black dblack@wobblini.net