From: Gavin Sinclair Date: 2003-09-19T23:03:31+09:00 Subject: Re: Removing "nil" entries from array On Friday, September 19, 2003, 11:59:04 PM, Joey wrote: > On 9/19/2003 9:54 AM, Thomas Adam wrote: >>...yet I re-ran my program using the same data file (unchanged) and now my >>array is being intermittently populated with "nil" values. Using "uniq()" >>doesn't remove them. Any ideas? >> >> > What about using delete_if? > a = [:foo, nil, :bar, :baz, nil, nil, "testing"] > a.delete_if {|x| x == nil} =>> [:foo, :bar, :baz, "testing"] > delete_if modifies the array in place. If you want non-destuctive, use > "reject" instead. Array#compact is designed for getting rid of nil values. Gavin