From: dblack@... Date: 2003-03-29T06:53:34+09:00 Subject: Re: Need #collect! on partial array Hi -- On Sat, 29 Mar 2003, Jim Freeze wrote: > Hi: > > Recently I needed to modify an array. > The array was part of a hash element, so > it had to be modified in place. > > #collect! would have been a great way to go, > but I did not need to modify the whole array. > > For example > > a=%w{one two three} > > a.collect! { |i| i.upcase } > > will modify the whole array. > > a[1..-1].collect! { |i| i.upcase } > > will modify the anonymous array created by a[1..-1], > but not a. > > This could have been solved with #collect_with_index! > but AFAIK, this does not exist. Citizens for MWI [map_with_index] welcomes you to its ranks :-) But I think it's been rejected. > Is there another way to achieve this same affect? You could do some variant of: (0...a.size).each {|i| } David -- David Alan Black home: dblack@superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav