From: dblack@... Date: 2002-12-16T02:07:51+09:00 Subject: Re: un-extending objects Hi -- On Mon, 16 Dec 2002, ts wrote: > Not tested > > class Object > def stretch(mod) > c = dup > c.extend(mod) > yield(c) > end > end I thought about dup, and avoided it partly because it always seems to raise issues about deep/shallow copy as well as just being (potentially) expensive. In this case, also, the resulting semantics have a different feel: obj.stretch(mod) {|o| o.blah ... } rather than: obj.stretch(mod) { obj.blah ... } The first one, to me, doesn't convey the sense that this object is being stretch'ed. And I think it would behave differently if, say, there were multiple references to the object, and you expected all references to be stretched. Picking up on the block param thing, though: in the non-dup version, perhaps 'yield self' would be a good idea, so one could chain them: arr.stretch(ArrayExtras) { arr.to_hash.stretch(HashExtras) { |h| p h.some_new_thing... } } (Getting *very* hypothetical here :-) Qu'est-ce qu'on y pense? David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav