What is the difference from using self in an instance method vs class method?
The keyword self in Ruby allows you to have access to the current object — the object that is receiving the current message. When using self for a class method, it sets an actual method for that class. Class methods cannot refer to any instances of that class. But with instance methods, they can be referred to any instances of that class. In order to use the instance methods, you would have to point yourself to any instances that are being executed.
Example Of Using Self In A Class Method

In the example, above self is used as a class method. On line 8, @@all is set to an empty array . On line 12, @@all is then shoveling that array into the passenger class. Finally on line 15, the method “Self.@@all” is returning all the instances in the array of the Passenger class. So if we call “Passenger.all”, it will return all the instances of that class.

Examples Of Using Self In A Instance Method

In this example, the instance method rides returns all the rides a passenger has taken. The instance method drivers uses rides as a helper method. Therefore, on line 28 and 29 it states :

This line is saying in this class we are going to take the rides method and collect all the drivers a passenger has ridden with. Therefore, if we call an object of the passenger class and the method, we will get all the drivers a passenger has ridden with.

In conclusion, the main difference from using Self in a class method vs an instance method is a class method can only be called by the class it is in and not by any instances. An instance method can be referred to any instances of that class.
