O'Reilly logo

Learn Ruby the Hard Way: A Simple and Idiomatic Introduction to the Imaginative World of Computational Thinking with Code, Third Edition, Video Enhanced Edition by Zed A. Shaw

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exercise 39. Hashes, Oh Lovely Hashes

Image

Now I have to hurt you with another container you can use, because once you learn this container a massive world of ultra-cool will be yours. It is the most useful container ever: the dictionary.

Ruby calls them “hashes”, which is short for “hashmaps.” Other languages call them “dictionaries.” I tend to use both names, but it doesn’t matter. What does matter is what hashs do when compared to arrays. You see, an array lets you do this:

Exercise 39 Ruby Session

?> things = ['a', 'b', 'c', 'd'] => ["a", "b", "c", "d"] >> puts things[1] b => nil >> things[1] = 'z' => "z" >> puts ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required