Ruby - Hash Hash Sorting

Introduction

To sort a hash, create your own method

def sorted_hash( aHash ) 
  return aHash.sort{ 
    |a,b| 
      a.to_s <=> b.to_s 
  } 
end 

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.