On Mar 26, 2007, at 10:18 AM, Ilan Berci wrote:
> senthil wrote:
>>
>>  Thanks for some of your replies for the lst post i need small
>> modification in that post .. i want to sort the salary in descending
>> order. i have explained the same quesion again....
>>
>
> I came up with this which is sub par as I test for a condition  
> twice so
> stay tuned for a better solution..
>
> irb(main):001:0> [['d',100],['c',200],['b',50],['a',100]].sort {|a,b|
> b[1]==a[1]?a[0]<=>b[0]:b[1]<=>a[1]}
> => [["c", 200], ["a", 100], ["d", 100], ["b", 50]]
>
> hope this helps
>
> ilan

Just to add a bit to this:  consider using .nonzero? for chained  
comparisons

[['d',100],['c',200],['b',50],['a',100]].
   sort {|a,b| (b[1]<=>a[1]).nonzero? || a[0]<=>b[0] }

-Rob

Rob Biedenharn		http://agileconsultingllc.com
Rob / AgileConsultingLLC.com