Iterate on Ruby hash (sorted and unsorted)

h = {”boy” => 1, “apple” => 2, “cat” => 3}

Will output:
cat => 3
boy => 1
apple => 2

To get sorted ruby hash output, do:

Will output:
apple => 2
boy => 1
cat => 3


These icons link to social bookmarking sites where readers can share and discover new web pages.

  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists
  • blinkbits
  • BlinkList

Leave a Comment