From: Paul Brannan Date: 2002-09-11T01:57:00+09:00 Subject: Re: ruby-dev summary 18111-18212 On Wed, Sep 11, 2002 at 12:22:58AM +0900, Yukihiro Matsumoto wrote: > |Interesting. Is this what "become" does in Smalltalk? > > It's not. I've heard Smalltalk "become" is too dangerous. > # perhaps I have to choose another name. Ideas? I think a lot of people will be surprised by this, so I agree it should probably be given a different name. Some ideas for a name: copy, copy_from, copy_state, xerox, replicate. What problems/limitations were there with the old style of only implementing clone in the derived class? While become() could be used to copy one object into another, it copies only internal state, so I can't really see myself calling it directly. > |if I want to implement dup/clone for an object in an extension, what is > |the correct way to do this so that it will work with both 1.6 and 1.7? > > define both clone and become, e.g. > > def become(orig) > # copy internal state > end > > def clone > c = super > c.become(self) > end > > in 1.7 become is called twice, but it should be OK. Interesting; I think that should work. It's a little inconvenient, though, and it would be nice if the interpreter gave me a warning, so if I define only clone() on Ruby 1.7 the code won't silently break. Paulk