From: RK Sentinel Date: 2009-01-24T19:03:24+09:00 Subject: Sorting array with nils I have been browsing but given answers are not suiting me. I hava a double dim array like a dataset. I thus *cannot* use compact since that would knock off rows. Some answers say a nil cannot be compared to another datatype so the question of putting such rows at the beginning or end does not arise. I am trying to check for nils and using a "false/true" or -1/1 etc but all are giving errors. Could someone help me out with this. def sort categ, column, descending=false d = get_records_for_category categ d = d.sort { |y,x| if descending if x[column].nil? true # <<<<------------- errors elsif y[column].nil? false else x[column] <=> y[column] end else if x[column].nil? 1 # <<<-------------- gives errors elsif y[column].nil? -1 else y[column] <=> x[column] end end } return d end Since its a double dim array, i cannot say what the datatype will be: can be string, fixnum, date or true/false. I figured since "A" <=> "B" reutrns -1,0 or 1, i should also put one of these in the loop but it throws an error. thanks. -- Posted via http://www.ruby-forum.com/.