Difference between Class and Instance Methods in Ruby.

There are two main classes of methods in Ruby. Class and Instance, both of these methods are used in different tasks. but, what's the difference between these two methods? and, how can we possibly use these classes on ruby?

Class methods are used to construct an object by creating a new instance of the class. Instance methods are the objects created by the class. The class methods are called by itself on the class by using def self.class_name_of_method, and instance methods are just called as a regular (method) instance of the class by using def name_of_method.

Is important to know that we cannot call an instance method on the same class. Also, we cannot call a class method on an instance.

--

--

Christian Bermeo
0 Followers

Software Engineer Student at Flatiron School