Learn Ruby
Instance Method
20.6
Lesson

Turn the car

Let’s add method turn to class Carmaker.

Run the code and we get the message The car is turning. We want the car to turn left sometimes and right sometimes.

When we call the turn method we should pass which side to turn.

car1.turn("left")
car1.turn("right")
car1.turn("left")

Method turn should accept the direction of turn.

Let’s change our code.

This concept of passing different values to the same method is called passing argument.

In this case we can say that method turn takes one argument. In the previous lesson we saw that the method gift also takes one argument.