I would use another data structure too:

k =3D ["MARCH", 1, 2,"JANUARY",3,4, "FEBRUARY",5,6,7,"DECEMBER",8,9, "OTHER=
"]
months =3D {}
tmp =3D []

k.each do |element|
  if element.kind_of? String
    months[element.to_sym] =3D tmp
    tmp =3D []
  else
    tmp << element
  end
end

months

This way, you will be able to retrieve the objects as:
          months[:JANUARY] #=3D> [1,2]

By the way, if you need it that way:

k =3D ["MARCH", 1, 2,"JANUARY",3,4, "FEBRUARY",5,6,7,"DECEMBER",8,9, "OTHER=
"]
months_array =3D []
tmp =3D []

k.each do |element|
  if element.kind_of? String
    months_array << element
    months_array =3D months_array + tmp
    tmp =3D []
  else
    tmp << element
  end
end

months_array

Hope I had helped in a way.

Daniel Gayt=E1n


2010/11/29 Robert Klemme <shortcutter / googlemail.com>

> On 11/29/2010 04:47 PM, Jim Burgess wrote:
>
>> Hi,
>>
>> I have an array consisting of "Event" objects, and string elements which
>> contain the names of months.
>> It looks like this:
>> [#<Event:0x4d4cf78>, #<Event:0x4d4d470>, "MARCH", #<Event:0x4d4dc08>,
>> #<Event:0x4d4e100>, "FEBRUARY", #<Event:0x4d4e898>,"JANUARY"]
>>
>> Currently the events precede the months they are ordered to.
>>
>> Is there any way to reverse this so that the months precede the
>> events?
>> Like this:
>> ["MARCH", #<Event:0x4d4cf78>, #<Event:0x4d4d470>,
>> "FEBRUARY",#<Event:0x4d4dc08>, #<Event:0x4d4e100>, "JANUARY",
>> #<Event:0x4d4e898>]
>>
>> 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.
>>
>> Can anyone point me in the right direction.
>> I am grateful for any help.
>>
>
> I would chose different data structures: if your events have a month wher=
e
> they are scheduled I would make the month an attribute of Event. Then you
> can sort your Event instances according to any criteria you like - includ=
ing
> month.  Mixing types in a collection can make handling that collection qu=
ite
> complex - as you are experiencing.
>
> Kind regards
>
>        robert
>
>