From: Kevin Smith Date: 2001-09-03T23:29:07+09:00 Subject: [ruby-talk:20778] Re: RCR: non-bang equivalent to []= --- Tobias Reif wrote: > > a = ['h','o','u','s','e'] > > new_array = a.with('m',0) > > p new_array # -> ['m','o','u','s','e'] > > > > or these (fragments can be combined freely): > > change, change_value, change_one, change_item, > change_element, > > replace, replace_value, ... > > > > (all plus ! version) > > > What do others suggest? Many of the Array methods are already bang-type methods, even though they don't have the bang: clear, delete, delete_at, delete_if, fill, pop, push, replace, shift, unshift. I keep thinking the name would have to be something like copy_and_set. Anything that doesn't say copy, or clone, just doesn't imply to me that it would make a copy. So, I just don't see the benefit of creating this shortcut method, especially since I can't think of a time when I have wanted it. However, I haven't found any easy way to deep-copy an array. If that really doesn't already exist, I'd like to see it added: a = ['h','o','u','s','e'] new_array = a.clone # same as: new_array = [] + a new_array[0] = 'm' p a # -> ['h','o','u','s','e'] p new_array # -> ['m','o','u','s','e'] Kevin __________________________________________________ Do You Yahoo!? Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger http://im.yahoo.com