From: Frederick Ros Date: 2005-12-13T21:01:00+09:00 Subject: Re: stable sort_by? Kroeger, Simon (ext) wrote: > Full Ack, > > obviously sort_by isn't stable: > > test = [[1, 'b'], [1, 'c'], [0, 'a']] > p test.sort_by{|t|t[0]} > > => [[0, "a"], [1, "c"], [1, "b"]] > (ruby 1.8.2 (2004-12-25) [i386-mswin32]) Hummm not sure to understand ... You asked for a sort on the first item ... So, in this case [1,"c"] and [1,"b"] are equivalent, and their order is un-important ... If you do value the order of the 2nd item of the array too, you just have to specify it : test = [[1, 'b'], [1, 'c'], [0, 'a']] p test.sort_by{|t| t } => [[0, "a"], [1, "b"], [1, "c"]] Best Regards, Fred -- Posted via http://www.ruby-forum.com/.