From: Tobias Reif Date: 2001-09-02T00:24:02+09:00 Subject: [ruby-talk:20671] corresponding "non-bang" method to []= Hi, There's "collect", and the bang version "collect!" AFAICS, []= is bang. What's the non-bang version? I'm trying to modify specific members of an array, depending on their position in the array ("second and last get a newline" etc.). I'm working my way through the docs, faqs, and the Pickaxe. Now after hours of trying, I only got it to work using a dirty hack. I'm looking for a nice way. So because in collect there is no index passed to the block, I need to use each_index, where I need to use []= to set the new value. (AFAIK) But I don't want to modify the original, because I need to modify it differently in another method starting from it's previous state. In pseudo-code: 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 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/