Learn Ruby
Class
19.2
Lesson

Coffee maker class definition

A coffee maker machine makes coffee. A coffee maker machine itself is not a coffee. However a coffee maker machine can produce a coffee.

Let’s create a class named Coffeemaker.

class Coffeemaker
end

Now we need to ask this Coffeemaker class to produce a coffee. In the last lesson we saw that we can make a car out of a class using the method new. So let’s use new here also to make a coffee out of Coffeemaker.

So far we have built coffee and car out ouf their classes. The things that a class makes are called instance. In this case coffee1 is an instance of class Coffeemaker. In the last lesson car1 was an instance of class Carmaker.

Let’s go over it again.

A class is something that builds or makes something. So far we have seen two classes - Carmaker and Coffeemaker. The things that are built by these classes are called instances. A car is an instance of the class Carmaker. A coffee is an instance of the class Coffeemaker.

I know all this class and instance things are still confusing. That’s why we will discuss it again in the next lesson.