Learn Ruby
Instance Method
20.7
Lesson

Hot coffee Cold Coffee

Let’s add method serve to class Coffeemaker.

When we run the code then we get the message This coffee is being served.

Some people want “hot” coffee and some people want “cold” coffee.

coffee1.serve("hot")
coffee1.serve("cold")

Now we are passing “condition” to serve method so we need to make changes to serve method to accept the type of coffee.

In this case method serve takes one argument. A method can also also take more than one argument as we will see in the next lesson.