From: Christopher Dicely Date: 2009-04-07T13:31:24+09:00 Subject: Re: how to sort a multi-elements array On 4/6/09, Alexey Zilber wrote: > Hi, > > Was going through these older posts and have a similar question. I > have a nested array that contains a date and a filename. I'm trying to > sort by file date. > > The array is in the form: > > SortedFiles = [ [200904031109, "filea.txt"], [200904031337, > "fileb.txt"], [200904031110, "filec.xt"] ] > > What I was trying to do was: > > SortedFiles.sort { |[[a,b],[x,y]] a < x | } > > That, unfortunately, did not work. I'm using Ruby 1.8.5 btw. Can anyone > help out? SortedFiles.sort_by {|date, fname| date} or: SortedFiles.sort {|record1,record2| record1[0]<=>record2[0]}