From: botp Date: 2007-08-27T00:53:36+09:00 Subject: Re: add outside variable to array elements On 8/25/07, Stefan Rusterholz wrote: > Pe�a, Botp wrote: > > ar2 = ar1.collect { |x| x<45000 ? (x + incVal) : x} > > or > > ar2 = ar1.collect { |x| if x<45000 then (x + incVal) else x end} > > or > > ar2 = ar1.select{|x| x<45000}.collect{|x| x + incVal} > > > > i usually prefer the last one, since i think like: "select those > > elements < 45000, then with those collections, increment each". but that > > is just me. > > > > welcome to ruby. > > kind regards -botp > > The last one is not equivalent to the other two. It will drop values >= > 45000. oops. mea culpa. what was i thinking again :( yes, pls ignore the last one. at least i may be right on the testing part :)) kind regards -botp