From: "David A. Black" Date: 2001-09-04T02:51:58+09:00 Subject: [ruby-talk:20796] Re: RCR: non-bang equivalent to []= Hello -- On Tue, 4 Sep 2001, Kevin Smith wrote: > --- ts wrote: > > >>>>> "K" == Kevin Smith writes: > > > > K> class Array > > K> def copy > > K> return []+self > > K> end > > K> end > > > > Probably I'm missing something but you have written > #clone > > No, you're not missing anything. I think this would be a > handy method to include in the core Array class. I think > the name copy is better than the name clone, because clone > has special meanings to people. > > It's not a killer, but it took me maybe twenty minutes to > figure out this simple way to copy an array. It seems like > a useful thing to do, and it's something I have wanted to > do in the past. > > Also, it could be improved to "fix" the problem you > mentioned earlier. If a contains itself, then a copy of a > should contain a copy of _itself_, and not of a. > Immediately after doing []+self, it should be easy to > replace all elements that are 'self' with references to the > newly-created array. > > Does anyone else think this is worth of RCR status? Are you suggesting changing #clone's name to #copy? David -- David Alan Black usually dblack@candle.superlink.net writing from dblack@saturn.superlink.net