From: Tobias Reif Date: 2001-09-02T02:22:12+09:00 Subject: [ruby-talk:20675] RCR: non-bang equivalent to []= Hi, RCR: I'm rying to modify specific items in a nested array, without modifying the original. I tried some variations, but most things that come to mind failed. There are ways to achive what I want (I found some hack that works for me), but I believe it would be good for the ease of use to introduce the following: # []= is bang; so a version of []= that doesn't modify the receiver would be cool. 1.1. Array#set_at position, new_value an_array.set_at(2, new_value) and maybe 1.2. Array#set_at! or 1.3. an_array.at(2) = new_value # "add a newline to the second and last item in the array" an_array.each_index do |x| new_val = an_array.at(x) + "\n" if (x == 2) or (x == (an_array.size - 1)) an_array.set_at(x,new_val) end end or even: an_array.each_index do |index,item| or an_array.collect |index,item| if (index == 2) or (index == (an_array.size - 1)) item + "\n" else item end end Tobi -- Tobias Reif http://www.pinkjuice.com/myDigitalProfile.xhtml go_to('www.ruby-lang.org').get(ruby).play.create.have_fun http://www.pinkjuice.com/ruby/