From: "Jesús Gabriel y Galán" Date: 2012-04-11T23:24:51+09:00 Subject: Re: A Beginner's Question about Metaprogramming On Wed, Apr 11, 2012 at 3:44 PM, Thufir wrote: > On Wed, 11 Apr 2012 19:56:27 +0900, Jan E. wrote: > >>> No. Singleton methods are methods that exist only for a single object. >> >> Well, the singleton methods of a class *are* the class methods. > > Can you clarify this?  In Java, class methods are declared with static. > In ruby, I believe it's @@, but the same upshot. No, @@ is to define class variables, which is a quite different things than class methods. > > There's a distinction between class methods and methods of a Singleton, > to my understanding.  Methods on a singleton are regular methods and > require the Singleton object to be instantiated, but are most definitely > not static methods.  I'm not sure about Ruby, but in Java you wouldn't > instantiate a Math object to call Math.sqrt() or whatever, that would be > nonsensical.  Class methods don't require an instance, while, to the > contrary, Singleton *is* an instance.  Or, rather, the only instance. > > From a usage standpoint, I think it's half a dozen of one, six of > another, but they're not the same at all. > > Please correct any misunderstandings I have. As Jan said, class methods are singleton methods where the object in which they are defined is the *class* object. Compare: a = [] def a.half_size size / 2 end This is a singleton method for that specific array object. class A def self.test puts "test method" end end Here, test is a singleton method for the object that is self in that context, that turns out to be class A. Remember that in Ruby classes are objects. Jesus.