Hi --

On Sat, 17 Feb 2007, Gary Wright wrote:

>
> On Feb 16, 2007, at 1:50 PM, Phrogz wrote:
>> Having said that, I personally would prefer for 3.dup to 'just work',
>> returning an object that is equivalent to the original. Just because
>> the new instance happens to be the same doesn't mean that it's bad -
>> as an immutable object, the only way to tell is via object_id, anyhow.
>
> I've come across this situation when writing generic code to do a
> 'deep copy'.  Instead of changing the semantics of #dup, why not have
> some other method that means 'make a copy if you can but if the object
> has immutable semantics then return a reference to self'.
>
> As for a name for such a method, how about Kernel#another ?

But self isn't other than self.

> I'm not sure how #dup, #clone, and #another should be related.  Perhaps
> #another should use #clone instead of #dup?  Maybe there should be another
> version of #another that uses clone semantics?

#another_another? :-)


David

-- 
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
    (See what readers are saying!  http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)