From: ptkwt@... (Phil Tomson) Date: 2004-09-14T10:09:54+09:00 Subject: Re: traits & roles In article <4581.218.214.1.200.1095117526.squirrel@webmail.imagineis.com>, Gavin Sinclair wrote: >Phil wrote: >> So you might have: >> >> class Baz >> end >> >> baz = Baz.new >> baz.extend Foo #baz now has Foo 'traits' >> >> ....and later you might want to do: >> baz.unextend Foo #remove the Foo 'traits' from baz >> >> ....later on you could add another set of traits to baz: >> baz.extend OtherTraits >> >> Of course there is no 'unextend', but there are probably ways to >> implement this. For example, you could get a list of all of the methods >> of Foo and undef them in the baz object (couldn't you?) > >I'd expect a proper implementation of 'unextend' to just "peel away a >layer of methods", not actually remove them. So... > > module Foo1 > def foo; "foo1"; end > end > > module Foo2 > def foo; "foo2"; end > end > > class X > end > > x = X.new > > x.foo # error > > x.extend Foo1 > x.foo # "foo1" > > x.extend Foo2 > x.foo # "foo2" > > x.unextend Foo2 > x.foo # "foo1" > Yes, you're right. This would be better behavior. Any idea how something like that could be implemented? Phil