Intro To Ruby Hashes Lab
Class hash some.
Intro to ruby hashes lab. Since ruby 1 9 hashes maintain the order in which they re stored. 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. This is called monkey patching.
What is monkey patching. The instructions and comments are designed to help you get the tests to pass. Access and modify data stored in a hash. Enjoy the videos and music you love upload original content and share it all with friends family and the world on youtube.
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. 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. 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.
Red font color or gray highlights indicate text that appears in the answers copy only. Many ruby programmers love to use it because it takes a little less space and it also looks a lot. It is a simple and flexible way to store structured values together and hashes are used all over the. If we create a file that reads.
Background scenario it is important to understand when continue reading. Monkey patching is the practice of re opening and modifying pre existing classes. In past versions of ruby you could not rely on hashes maintaining order. 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. So ruby already has a hash class the instances of which you ve been working with in the past two units. As of ruby 1 9 the order of putting things into the hash is maintained. Contribute to learn co students phrg ruby intro to hashes lab pca 000 development by creating an account on github.
In this lab you ll be modifying ruby s hash class. Employee salary. Add new data to a hash. One of the most fundamental and important types in the ruby programming language is the hash.