From: Gary Wright Date: 2009-07-19T02:57:10+09:00 Subject: Re: Hash of Hash of Arrays Question On Jul 18, 2009, at 12:43 PM, Älphä Blüë wrote: > Does find exactly what I need for any future needs when required. So, > at least I learned something. Now if I could just figure out how to > sort a hash.. Prior to Ruby 1.9, hashes are unsorted. In Ruby 1.9, hashes are maintained in insertion order. That is to say, if you iterate over the hash you'll get the key/value pairs in the order in which they were inserted into the hash. If you want to iterate over a hash according to some other order you'll need to do something like: hash = {2=>1, 1=>0, 3=>4} hash.sort_by {|k,v| k }.each { |k,v| puts "key: #{k}, value: #{v}" } key: 1, value: 0 key: 2, value: 1 key: 3, value: 4 Note that sort_by doesn't return a hash but instead returns an array of key/value pairs: >> hash.sort_by { |k,v| v } => [[1, 0], [2, 1], [3, 4]] Gary Wright