From: Chris Dutton Date: 2004-04-21T14:14:07+09:00 Subject: Re: efficient collect+compact ? Martin Pirker wrote: > Hello... > > What's the most efficient way for > > puts [1,2,3,4,5,6,7,8,9,10].collect{ |x| next if x % 2 == 0; x+10 }.compact > or > puts [1,2,3,4,5,6,7,8,9,10].collect!{ |x| next if x % 2 == 0; x+10 }.compact! Hmmm... not sure I can offer any help in increasing performance, but it seems perhaps the following is a bit cleaner: puts (1..10).to_a.collect{ |x| x + 10 if x % 2 == 0 }.compact