From: Rahul Kumar Date: 2010-10-13T21:53:53+09:00 Subject: Re: sort_by: multiple fields with reverse sort When i sat down to code, i realized that i could not just put the sort_keys list to sort_by, i would have to unroll the sort_keys array. So, i might as well use sort. This seems to work in the small case i have. Could someone comment on this, and suggest cleaner better way to do. Thanks. b=[ ["radio", 30, 5], ["radio", 20, 5], ["archie", 20, 5], ["newton", 10, 3] ] sort_keys=[1,0] rev_flag = [true, false] c=b.sort{|x,y| res = 0 sort_keys.each_with_index { |e,i| if rev_flag[i] res = y[e] <=> x[e] else res = x[e] <=> y[e] end break if res != 0 } res } c -- Posted via http://www.ruby-forum.com/.