From: Michael Joner Date: 2002-01-06T10:34:57+09:00 Subject: [ruby-talk:30320] Sorting a Hash by value of integer stored in the Hash I have a program which creates a Hash array. The ultimate result is a word as the key and an integer as the value. I'd like to sort by the value in the Hash, then print the ten highest values and their associated keys. I understand that there is a sort Method but I'm not sure how to get it to work on a Hash. I know that if my data were simply stored in an array I could use: myArray.sort { |a,b| b <=> a } So I've tried the same technique on the Hash: myHash.sort { |a,b| b <=> a } Printing the first ten elements of the resulting object (which was an array) returned words starting with z and then y (in reverse alphabetical) and the associated value, run together. This isn't what I'm trying to get. The sort apparently was performed on the keys, but I want to do sort on the values. Is there a way to do this? Mike