From: Nico Ritsche Date: 2008-01-30T01:13:19+09:00 Subject: Re: Hash Sorting Rodrigo Kochenburger wrote: >> pi_array_sorted = >> { 'general_event_types', �[GeneralEventType1, GeneralEventType2, ..], >> � 'prices', � � � � � � � [Price1, Price2, ..], >> � 'specific_event_types', [SpecificEventType1, SpecificEventType2, ..], >> � 'general_event_types', �[Teacher1, Teacher2, ..] } >> >> So the keys should be in alphabetical order, but they arent, at least >> not when I iterate over the array using >> > > This code above doesn't create an array, it creates an Hash, and Hash > doesn't preserve order. > Do the following: > > pi_array_sorted = [ > ['general_event_types', [GeneralEventType1, > GeneralEventType2, ..]], > ['prices', [Price1, Price2, ..]], > ['specific_event_types', [SpecificEventType1, > SpecificEventType2, ..]], > ['general_event_types', [Teacher1, Teacher2, ..]] > ] > > pi_array_sorted.each do |key,value| > # do stuff here > end > > Cheers Hi Rodrigo, sorry, maybe the code was confusing, I just wanted to visualize the result array I like to get after sorting. So the "pi_array_sorted =" shouldn't be an assignement and I used the wrong brakets. Thanks all for your comments, but unfortunately concerning the sorting issue I'm not a single step further. Cheers, Nico -- Posted via http://www.ruby-forum.com/.