From: Daniel Berger Date: 2005-12-09T03:21:10+09:00 Subject: Re: ordered/sorted hash Gene Tani wrote: > Steve Litt wrote: > >>On Thursday 08 December 2005 12:37 pm, robertj wrote: >> >>>hi, >>> >>>is there anywhere a class that does soemthing >>>akin to java.util.SortedMap? that is sorting >>>and iterating over the hash in the order of its >>>keys. >> >>When I tried it, it seemed that Ruby automatically sorted the keys. I'm not >>sure if this is what you want, but see this: >> >>http://www.troubleshooters.com/codecorn/ruby/basictutorial.htm#_Hashes >> > > > Not sure what "it" is, but Hash#sort will convert the hash to a list of > lists, sorted by their keys True, but unless you need the values stored in order internally, just do this: hash.sort.each{ |e| puts "#{e[0]} => #{e[1]}" } Regards, Dan