From: Christopher Dicely Date: 2008-03-29T15:29:18+09:00 Subject: Re: Help on best way to gather/sort results ? On Fri, Mar 28, 2008 at 10:49 PM, Tony De wrote: > > Tony De wrote: > > Todd Benson wrote: > >> On Sat, Mar 29, 2008 at 12:02 AM, Tony De wrote: > >>> have for qmail. So, I've got a working prototype. If you could help me > >>> on my sort and if you have any other comments/suggestions to throw my > >>> way I'm sure I could learn a thing or two. Being new to ruby, there's a > >>> lot of new ideas here. Thank guys. > >>> > >> > >> Being a little lazy at the moment to go through the code, have you > >> looked at #sort_by{}? > >> > >> Todd > > > > I believe I ran across it but I recall it blew up when I worked with it. > > Likely an issue with my as the unskilled ruby coder than the method > > itself. I'll take another look. Thanks > > > > tonyd > > Ok, tried this @results.sort_by { |a| a[1] } - thinking that I want to > sort on the second element in my array "Source". No sort was performed > at all. Scratching my head.. Did you capture the result? #sort and #sort_by are non-destructive, so this: --- a= [ [0,3], [4,1], [5,2]] a.sort_by {|i| i[1]} puts a.inspect --- gives: "[[0,3],[4,1],[5,2]]" but this: --- a= [ [0,3], [4,1], [5,2]] b=a.sort_by {|i| i[1]} puts b.inspect --- gives: "[[4,1],[5,2],[0,3]]" There is a destructive version of #sort (#sort!), but not of #sort_by.