From: Martin Pirker Date: 2004-04-21T10:29:07+09:00 Subject: efficient collect+compact ? 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! Or: I want to iterate over all array elements, process them, decide whether the result is any good, and keep only the good ones. It's ok doing that by chaining collect+compact, but I ponder this must be slow/inefficient for array with xxxxx elements. I read Array and Enumerable docs, have I missed something[1] or does a straight "collect everything but nil" function not exist? Martin [1] (it's already past 3am but I remember searching the same thing sometime ago)