Ruby - Hash Hash Sorting


To sort a hash, create your own method

def sorted_hash( aHash ) 
  return aHash.sort{ 
      a.to_s <=> b.to_s 

This performs the sort based on the string representation (to_s) of each key in the hash.

The Hash sort method converts the hash to a nested array of [key, value] arrays and sorts them using the Array sort method.