puts h.keys[0]
#=> fruit
The above code assumes we created the hash like so :
h = {"fruit" => "banana", "drink" => "water"}
Note: The hash item can be assigned an integer value as a key name e.g.
h = {12 => "grapes", 3 => "peach", 0 => "banana"}
16794 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
puts h.keys[0]
h = {"fruit" => "banana", "drink" => "water"}
h = {12 => "grapes", 3 => "peach", 0 => "banana"}
You need to create an account or log in to post comments to this site.