From: Marnen Laibow-Koser Date: 2009-10-31T02:12:34+09:00 Subject: Re: two stage array sorting Tim Ferrell wrote: > > I have an array of strings like so: > > Tuesday 12:00 AM > Sunday 9:00 AM > Tuesday 3:00 PM > Friday 7:30 AM > Wednesday 5:00 PM > > and I want the array sorted by day name and then time. Is it possible to > do this without resorting to a two stage process? Currently I am > breaking the array out into arrays by day and sorting those by time and > then reassembling... it just feels dirty :-) > > Ideas? array.sort_by{|s| s.split(' ')} Of couse, that will do alphabetic sorting in each half. If you need time sorting, my suggestion would be to use a date parsing function in the sort_by block. > > Thanks much... Best, -- Marnen Laibow-Koser http://www.marnen.org marnen@marnen.org -- Posted via http://www.ruby-forum.com/.