From: Vance A Heron Date: 2005-08-21T20:19:28+09:00 Subject: Re: Problem with sort! The real function was a little more complex than could be done by sort by. I tried to generate a smaller example, and confused myself. I refactored a little to reduce duplicating code - basically I have 2 separate sort methods, depending on a value in the data - but they're substantially the same. Anyway, by putting the common code in a method and having sort do something like vals.sort!{|a,b| sortfunc(a,b,sortflag) } things seem to work. Thanks to the list for all the help. Hopefully my next problem/puzzle will be more interesting. V On Sat, 2005-08-20 at 10:26 +0900, William James wrote: > Vance A Heron wrote: > > > puts "\nSort to new array" > > b = a.sort{ |a, b| a[0] <=> b[0] } > > b.each{|v| puts "class(#{v.class}) #{v[0]}, #{v[1]}"} > > It's simpler with sort_by: > > b = a.sort_by{ |x| x[0] } > >