The first thing you should know about Ruby is that there are no class methods. What we commonly refer to as a "class method" is simply a regular singleton method. Singleton methods can be found on any object; classes aren't required.
In Ruby, a method is a collection of expressions that returns a value. You can structure your code within a method into subroutines that can be conveniently called from other parts of the application.
In object-oriented programming, a class is used to describe one or more objects. It's used to create or instantiate certain objects within a program. While each object is made up of a single class, that same class can be utilized to make many objects.
Instance methods require a class instance and have access to it via self. A class instance is not required for class methods. They can't get to the instance (self), but they can get to the class using the cls command.
Share a personalized message with your friends.