It s important that you know this because if you are ever working with an older version of ruby anything before ruby 1 9 you cannot rely on the hashes being in any specific order.
Intro to ruby hashes lab.
So ruby already has a hash class the instances of which you ve been working with in the past two units.
Up to a certain version of ruby the syntax that uses hash rockets was the only syntax to create hashes and it works the same for all hashes no matter what kinds of objects you use as keys.
Class hash some.
It is a simple and flexible way to store structured values together and hashes are used all over the.
Red font color or gray highlights indicate text that appears in the answers copy only.
Ruby hashes a hash is a collection of key value pairs like this.
Employee salary.
Objectives use a hashing program to verify the integrity of data.
The instructions and comments are designed to help you get the tests to pass.
This is kind of weird because computer science 101 you re used to the fact that hashes or in other languages called maps or dictionaries the order of putting stuff in there is not maintained.
This is called monkey patching.
Monkey patching is the practice of re opening and modifying pre existing classes.
A note on hash order.
1 2 1 3 lab compare data with a hash answers lab compare data with a hash answers version answers note.
As of ruby 1 9 the order of putting things into the hash is maintained.
Many ruby programmers love to use it because it takes a little less space and it also looks a lot.
Access and modify data stored in a hash.
It is similar to an array except that indexing is done via arbitrary keys of any.
Fork and clone this lab and run the test suite with the learn command.
Since ruby 1 9 hashes maintain the order in which they re stored.
In past versions of ruby you could not rely on hashes maintaining order.
Enjoy the videos and music you love upload original content and share it all with friends family and the world on youtube.
Background scenario it is important to understand when continue reading.
One of the most fundamental and important types in the ruby programming language is the hash.
Pay attention to the test suite for this lab.
In this lab you ll be modifying ruby s hash class.
What is monkey patching.
Add new data to a hash.