Hello and welcome to this lecture on this lecture harbi explaining to you how to use each method.
Him the Ruby programming language.
What does the heat method do.
It may it is basically used to access Harry objets laws will use to access it up just in a hash every
Harry and has Ruby is basically an object and each of them have their own built in methods and they
each method also is built in to but they erase and also the hash objects.
Each method take theme to arguments an element and a block.
So this is an example here.
We've got a variable there or C T and we are using the each method to access the members of their Arey.
So they say it is the salary and we are using the Puts to display each city and then we end the statements.
I'm going to show you how this work using the ruby interactive tool.
I have caught the ruby interactive tool open so I'm going to start by creatine.
Hillary I'm going to create a record 15th
and I'm going to give it the value I'm going to set it free and I include the objets for Arey.
Ah so London.
Now the first sitting.
I'm next sitting.
I'll say New York.
Next city I'll see Frankfurt.
Now close me.
Hurry.
So we now have Hillary.
So now I want to implement the eight method s c c d quoll in the array.
Now the seat is dupped.
I'm trying to access each object in that Harry Santo's see teeth dot each and then they do and in between
the pipes the pipes is just a symbol next to the Z key inbetween the pipe.
Passing the element are passing in city.
Press Enter.
This time I want to display some text on the screen so I use the PUDs typing sitting.
So each year each method will get each member that Harry displayed on the screen.
And I need to end the statement.
So Ruby Ruby can action the request a presenter as he can see each member of the Arey has been listed.
So the each method is basically used to access members off an array.
You can use this bit a hash as well.
In the example I chose some illustrate it the element contained within the pipe which is in this case
the city is similar to a place holder.
So whatever you put in the pipes is used in the block to represent each element of an array in turn.
The block is the line of code that is executed on each of the three items and if handled the element
to process.
So that's how it works.
So the process will work the same way for he has.
So you can get it to return the key and a value a fit for this next hour.
Thanks for watching.
Hmm bye for now.