From: sto.mar@... Date: 2012-11-30T15:28:47+09:00 Subject: Re: Ordered Hash (v. 1.8) Am 30.11.2012 07:19, schrieb Harry Kakueki: >> creation. However, what I'd really like to do is, after the hash has >> been created, sort it on the key in a manner similar to the way that I >> would sort an array with the sort!() method and then preserve the sorted >> order. Any ideas on how I might accomplish that feat? Thanks for any >> input. >> >> ... doug > > > Does this work? > > > h = {} > arr = ["t","c","h","b","l"] > arr.each{|x| h[x] = x + "ook"} > > h = Hash[h.sort] > p h #> {"b"=>"book", "c"=>"cook", "h"=>"hook", "l"=>"look", "t"=>"took"} not in Ruby 1.8! And in 1.9 you would have to recreate the complete hash for each key-value pair that is added. --