For example, we have many instances of class String and we want to define some special methods for only a specific instance, but don’t want the others (same class) have these methods. Ruby supports us to do this by the singleton class.
- Is used for extending methods for an specific instance (note that
module
,class
also are instances ofModule
,Class
) - To get the instance’s singleton class, call
[instance].singleton_class
- To see which function is belonged to the singleton class called
[instance].singleton_methods
- The singleton class could also have its singleton class