From: Mauricio Fernandez Date: 2006-08-29T17:13:03+09:00 Subject: Re: Partial append_features? On Tue, Aug 29, 2006 at 08:15:47AM +0900, Eero Saynatkari wrote: > Robert Dober wrote: > > unfortunately that approach undefines eralier defined methods in the > > appendee, especially inherited ones :( > > I guess that could be fixed but the code will become rather clumsy. > > Heh, take another look: > > new_mod = Module.new # Only this anonymous is affected > new_mod.module_eval do > include mod > methods_to_remove.each { |meth| undef_method meth } > end > > A rather nice solution. I think this is what he meant: RUBY_VERSION # => "1.8.5" class X; def foo; "X#foo" end end class Y < X; end module M; def foo; "M#foo" end end N = Module.new N.module_eval do include M undef_method :foo end y = Y.new y.foo # => "X#foo" class Y; include N end y.foo # => # ~> -:14: undefined method `foo' for # (NoMethodError) IMO it's better to have the last call to #foo return X#foo. You can do that by cloning the module then using remove_method on the copy. -- Mauricio Fernandez - http://eigenclass.org - singular Ruby