From: Robert Dober Date: 2006-08-29T17:10:10+09:00 Subject: Re: Partial append_features? ------=_Part_4712_17717475.1156839007708 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 8/29/06, Eero Saynatkari wrote: > > Robert Dober wrote: > > On 8/28/06, Logan Capaldo 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: That is needless, I do not understand the code ;) Ruby does however: 508/31 > cat append.rb && ./append.rb #!/usr/local/bin/ruby -w class Module def append_from( mod, *methods_to_keep ) methods_to_keep.map! { |m| m.to_s } methods_to_remove =3D mod.instance_methods(false) - methods_to_keep new_mod =3D Module.new new_mod.module_eval do include mod methods_to_remove.each { |meth| undef_method meth } end include new_mod end end class Base def c puts "inherited c" end end module M def a puts "a" end def c puts "c" end end class A < Base append_from M, :a end a =3D A.new a.a a.c a ./append.rb:38: undefined method `c' for # (NoMethodError) new_mod =3D Module.new # Only this anonymous is affected > new_mod.module_eval do > include mod # The appender (not appendee, sorry I wrote this at > 1:00) is the receiver methods_to_remove.each { |meth| undef_method meth } and thus undef_method also undefines the method in the receiver that should be clear from the design of the solution. I cannot fix it but I guess Logan could end > > A rather nice solution. Well I like Logan's posts a lot and this too, it is interesting code, but sorry if I fail to agree it is not a solution. > > Cheers Robert --=20 Deux choses sont infinies : l'univers et la b=EAtise humaine ; en ce qui concerne l'univers, je n'en ai pas acquis la certitude absolue. - Albert Einstein ------=_Part_4712_17717475.1156839007708--