From: daz Date: 2004-07-18T10:57:11+09:00 Subject: Re: [QUESTION] : about class method Kurk Lord wrote: > Hi all, > > can somebody tell me if a class method can call (or use) a instance method ? > Example : > > class Foo > @@count = 0 > > def bar > @@count = @@count + 1 > end > > def Foo.suck > bar > end > end > You could arrange the "bar" instance method so that it calls a class method to do the class-specific operation, making it available from either level. class Foo @@count = 0 def Foo.suck bar end def Foo.bar @@count = @@count + 1 # other (bar) class stuff p [:count, @@count] end def bar Foo.bar # other (bar) instance stuff p ['#bar', @@count] end end Foo.suck #-> [:count, 1] Foo.suck #-> [:count, 2] Foo.new.bar #-> [:count, 3] #-> ["#bar", 3] :daz