Archive for May, 2007

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


Comments

Capitalize the first character of multi word string

The following sample of code capitalizes the first character of every word in a string.

And you can do the ruby string capitalization in this way (from David Felstead)


Comments (7)

Next entries »