From: Dick Davies Date: 2008-09-18T19:18:17+09:00 Subject: Re: Preserve insert order in a Hash On Thu, Sep 18, 2008 at 11:13 AM, Me Me wrote: > Thomas B. wrote: >> Peņa, Botp wrote: >>> From: Me Me [mailto:emanuelef@tiscali.it] >>> # I would like to know if it's possible to insert values in a Hash and >>> # then extract all of them in the same insertion order. >>> >>> only in ruby 1.9 >> >> Could anybody explain why this feature was added? Isn't it going to slow >> down the operations on the Hash? I think it is useless to mix Array with >> Hash. >> >> TPR. > > well, basically I just need a Hash to use String as indexes like > > sourceInfo = Hash.new > sourceInfo["var1"]=123 > sourceInfo["var2"]=2 > sourceInfo["var3"]=3 > sourceInfo["var4"]=23 > > and then print them in the exact order of insertion Can't you just sort them on the way out? i.e. sourceinfo.keys.sort.each { |k| sourceinfo[k].do_stuff } -- Rasputnik :: Jack of All Trades - Master of Nuns http://number9.hellooperator.net/