1.

What Is A Ruby Singleton Method ?

Answer»

A METHOD which belongs to a single object rather than to an entire class and other objects.

Before explaining about singleton methods I would LIKE to give a small introduction about class methods.

Class method: When you write your own class methods you do so by prefacing the method NAME with the name of the class.

There are three ways to write a class method.

  1. The first way is to preface the class name with the method name(ClassMethods.method1).
  2. The second way is to preface the self keyword with the method name(self.method2).
  3. The third way is writing a sepetare class INSIDE the class which contains the methods (class &LT;< self).

A method which belongs to a single object rather than to an entire class and other objects.

Before explaining about singleton methods I would like to give a small introduction about class methods.

Class method: When you write your own class methods you do so by prefacing the method name with the name of the class.

There are three ways to write a class method.



Discussion

No Comment Found