Hello and welcome to this lecture or anything to be explaining what hashes are what is a hat in some
programming languages it is referred to as a dictionary.
Ruby Ruby just refers to it as the house.
He has basically Ruby.
He is an on ordered object index collection of objects.
So in comparison two and three and three is an ordered collection of objects while a house is not ordered.
So the objet in house you cannot guarantee the order they will be.
Also while in an array you access the value base on the indexed with a hash you reference it find the
object.
We will have a key value.
So the key will have a corresponding value.
So the key difference between an array and a Hash is that Flurry is an ordered collection and it has
is an ordered collect.
You can reference he has via the objet in the key value pairs.
This will make more sense when we go on to create an example hash shortly.
Hash is identified.
My curly braces who when you create a hash you have to have include curlee process so you create a hash.
Basically the same way you would create a ring.
So you start with a name.
So I'm going to create a hash and I'm going to call it cars or car.
Make a car single up and set it to the airport to and then need the curly braces so you need the curly
braces in order to pull the plug.
It's inside the house so we have to define the key and then we defined a value.
So the key the first key unguents defined here is going to be the model of the car.
So type in model and enclose that in quotes and then you do an equal to and greater than sign.
When you do that now you have to give it a value.
So we've given it the we've got the key.
Now we need to add the value.
So the value surrounded input.
So my value here is going to be porsh
P R C H E porsh so that is one value.
That's the value of one object and do a comma.
If you want to add more say I want to add a column.
So you do.
Quotes followed by the word caller and then an equal to and then a greater than sign and then the value
of the caller.
So I see.
And you can go on until you know you exhausted the list but this is just an example.
So once you done it does poorly are the curly braces to close.
They have a few press enter it shows you that I've created a hash and this is a key for the first object
and that is a value second object.
This is the key that is of value.
This is all a means by key value.
P appears in pairs but they each value is object value object value here.
This object key this referred to as the key and it has a corresponding value.
What an array wait to access the octave in said array used the index with the hash.
You can use the key.
So if I type in the name of the hash which is car and then in square bracket I just type in in quotes
the name of what I'm looking for so I see a model include a square bracket and actually return posh
he can see is giving me the value of push I've typed in the key.
It's giving me value.
So in comparison with I raise you use the objects the key in the object to access the value outside
access the values inside the hash.
You can also access the key if you want it to access the key.
For example I can typing car dot key
and then just to type in the name of the key.
People
see it and press enter.
That is giving me a model so you can also do it this way.
All right so that's basically the kid defend it in an RV and it has to if you want something that you're
not you don't care what order then you can use the hash if you want something that is structured to
want a certain order.
Then Harry is the way to go.
So there's a lot you can do with hashes.
It works similarly to areas where you can manipulate them just as you would agree as well.
So that's it for this brief introduction to.
He has.
You can read more about it on the ruby documentation.
Many thanks for watching.
Bye for now.