From: "T. Onoma" Date: 2004-08-29T13:39:57+09:00 Subject: Re: Question about defining class methods On Sunday 29 August 2004 12:15 am, Robo wrote: > When defining class methods, are these two ways the same? Is there a > preference on which one should be use? > > class Monkey > def self.method1 > puts "method1" > end > > def Monkey.method2 > puts "method2" > end > end Identical. > I would think self.method1 is more preferable 'cos it doesn't have to > get rename when the class name gets change. True. > Also, I see them get call in two different ways, Monkey.method1 and > Monkey::method1. Both seems to work, are they identical? Is there an > idiom on which way should be use? They are the same too. The only time they may differ is when a method begins with a capital letter (which is very rare) then Monkey::Method1 would not find it b/c it was looking for a constant called Method1 instead, to fix just add (), i.e. Monkey::Method1(). T. > Robo -- T.