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.
Intro to ruby hashes lab.
Objectives use a hashing program to verify the integrity of data.
Access and modify data stored in a hash.
Then a few years back a new syntax was introduced.
It is a simple and flexible way to store structured values together and hashes are used all over the.
This is called monkey patching.
Pay attention to the test suite for this lab.
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.
Many ruby programmers love to use it because it takes a little less space and it also looks a lot.
A note on hash order.
What is monkey patching.
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.
In past versions of ruby you could not rely on hashes maintaining order.
In this lab you ll be modifying ruby s hash class.
1 2 1 3 lab compare data with a hash answers lab compare data with a hash answers version answers note.
Monkey patching is the practice of re opening and modifying pre existing classes.
Red font color or gray highlights indicate text that appears in the answers copy only.
Enjoy the videos and music you love upload original content and share it all with friends family and the world on youtube.
If we create a file that reads.
So ruby already has a hash class the instances of which you ve been working with in the past two units.
Since ruby 1 9 hashes maintain the order in which they re stored.
Class hash some.
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.
It is similar to an array except that indexing is done via arbitrary keys of any.
Ruby hashes a hash is a collection of key value pairs like this.
Contribute to learn co students phrg ruby intro to hashes lab pca 000 development by creating an account on github.
The instructions and comments are designed to help you get the tests to pass.
Add new data to a hash.