attr_reader writer and accessor
24.1
Lesson

Method to return instance variable

Let’s say that the instance of CoffeeMaker wants to access the condition of coffee. But there is a problem. Instances of CoffeeMaker can’t access instance variables. Only the methods can access instance variables. Let’s see an example.

In the below case we are getting error undefined method condition.

In order to fix this problem we can create a method which will return the instance variable.

Now the code will work because we added a method called condition which is returning the instance variable @condition.