>>>>> "David" == David Alan Black <dblack / candle.superlink.net> writes:
David> I don't get the @@use_original logic. When would the first
David> (true) part of the 'if' get executed? The only thing that
David> ever happens when @@use_original is true is for the poser's
David> #new to get called. And that #new, presumably, doesn't
David> know or care about @@use_original.
If the posing class is a subclass of the original, then the original's
version of new is invoked from within the replacement. The test is
required to prevent infinite recursion. If you don't ask a subclass
to pose as its parent, then you can avoid the extra logic.
David> I think you could economize on "<<" operators :-) though
David> I'm not 100% sure this code does exactly what yours
David> does... see what you think:
Your unpose is an improvement. Obviously "self.class_eval" isn't
needed.
In pose, you dropped the tricky logic needed for subclass support.
You also handle block arguments to new (which I missed). You also
moved to the error message to inside the instance_eval and replaced
"#{other_class.name}" with just "#{name}". Since the string in
interpolated before being passed to instance_eval, the "name" method
is invoked on the wrong object and the wrong class name appears in the
error message.
Other that that, they look equivalent to me.
David> (And I wonder whether Ruby has some incredible, three-line
David> equivalent up its sleeve....)
I suppose you've seen Matz's one-liner responce.
He takes all the fun out of things. Sigh. :-)
--
-- Jim Weirich jweirich / one.net http://w3.one.net/~jweirich
---------------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)