From: Brian Candler Date: 2010-11-30T21:26:50+09:00 Subject: Re: Help sorting an array Jim Burgess wrote in post #964771: > Is there any way to reverse this so that the months precede the > events? > Like this: > ["MARCH", #, #, > "FEBRUARY",#, #, "JANUARY", > #] > > I have been scouring the documentation for ages and have also googled > everything I can think of (e.g. Array#split) to try and find a solution, > but with no luck. If your Event has an accessor which shows the month of that object as a String, then you could do something like this: arr = arr.sort_by { |e| e.is_a?(Event) ? [1,e.month] : [0,e] } However, a heterogenous (mixed) list is not a convenient data structure to work with, as you've probably found. There may be a better way to group this data, depending on what you plan to do with it. For example, you could build a hash of month => [array of events for that month]. or a nested array of [[month, [events]], [month, [events]], ... ] -- Posted via http://www.ruby-forum.com/.