From: Alexey Verkhovsky Date: 2004-07-18T07:28:22+09:00 Subject: Re: [QUESTION] : about class method On Sun, 2004-07-18 at 01:17, Alexey Verkhovsky wrote: > On Sun, 2004-07-18 at 01:12, Kurk Lord wrote: > > can somebody tell me if a class method can call (or use) a instance method ? > > WHICH instance of Foo would you expect it to call? Sorry, hit "send" too fast. Extended answer to your question is as follows: Class Foo in your example is an object (a constant, actually), which has the methods defined as Foo.method, plus methods of Class (also a constant, superclass of Foo). Foo.new is more or less a factory method that can create objects with some behaviors grouped together within class Foo / end block. Objects created by Foo.new know who created them (Foo.new.class == Foo), but Foo itself doesn't implicitly remember the objects it creates. So, method like your Foo.suck can call an instance method only if it obtains a reference to that instance from somewhere. E.g., class Foo def initialize @@lastCreated = self end def bar # do something end def Foo.suck (@@lastCreated || Foo.new).bar # ^ ^ # Need to know which instance to call end end Also worth noting, you cannot call private instance methods from within class methods in Ruby (in Java you can). Best regards, Alexey Verkhovsky