From: ts Date: 2003-05-09T21:33:17+09:00 Subject: Re: Can a global be a constant? >>>>> "J" == Jim Freeze writes: J> Why does an object (in this case a class object) J> have an associated singleton class? Well, it's more * an object has a class * a class is an object ===> a class has a class Now you have 2 possibilities 1) all classes have the same class : this just stupid, because if you want to define the method ::new all classes will inherit the same method 2) each class has a specific class ==> this class has only *one* object (the class) ==> this is a singleton class a singleton class is just a class associated with one unique object. methods defined in a singleton class give methods specific to this object (this is really simplified) J> Don't objects J> just have single methods added to them? Where do you store these methods ? What do you do when someone write ? module A def a puts "a" end end a = [] a.extend A a.a a singleton class is an easy way to solve these problems, because when you write 'a.extend(A)' ruby has made the include in the singleton class associated with 'a' and you have something which is usefull, simple and coherent (another argument against the multi-dispatch :-)))) Guy Decoux