Tag Archives: hash

Ruby Hashes

Hashes in Ruby are a helpful way to organize information. As can be seen in the screenshot below, I’ve created a new hash, named it example, and given it a couple keys and values to start. To create your own hash, just pick the name you want it to be called and set that equal to Hash.new. Since Ruby is case-sensitive, it’s important to remember to capitalize Hash.new. To set keys and values, use the format: hashname[“key”] = “value”. In my example hash, I’ve created the keys “cold” and “hot” and given them values of “pluto” and “sun” respectively.

Screen shot 2013-11-15 at 8.47.33 AM

Next, you can get input from the user and add it to the hash as  a key or a value.

Screen shot 2013-11-15 at 8.53.04 AM

Continue reading

Let others know too...Email this to someoneShare on FacebookTweet about this on TwitterShare on LinkedInShare on Google+Share on Tumblr