On Fri, Nov 30, 2012 at 3:34 PM,  <[email protected]> wrote:
> Am 30.11.2012 08:09, schrieb Harry Kakueki:
>
>
>> # If you want to also keep the original order, maybe this is worth a look.
>> # I'm using 1.9 so I can't test it for your setup.
>>
>> class Hash
>>    def myway
>>      Hash[*sort.flatten]  #Ruby 1.8 ?
>>      #Hash[sort]   # Ruby1.9
>>    end
>> end
>
>
> This does not work in 1.8, because hashes in 1.8 do
> *not* keep the insertion order.

That's why Doug had installed the OrderedHash Gem I guess.  So with a
little change that should work:

# untested:
OrderedHash[*sort.flatten]

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

-- You received this message because you are subscribed to the Google Groups 
ruby-talk-google group. To post to this group, send email to 
[email protected]. To unsubscribe from this group, send email 
to [email protected]. For more options, visit this 
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en

Reply via email to