small medium large xlarge

11 Aug 2008, 13:34
KenA (16 posts)

Hello. In the AWDR book, page 97 there´s an explanation for the keyword “self”: <blockquote> (…we want to call it on the class as a whole, not on any particular instance…) </blockquote>

Is it the same as the static method when we don´t need an instance of the class, thus we can just call the class.method? and the main reason because we don´t wan´t to instantiate a class is because we at a particular moment we don´t need the class attributes and all other methods loaded in memory?

11 Aug 2008, 14:04
Sam Ruby (633 posts)

If you come from a C++/Java/C# background (languages which use the term ‘static method’), then yes, a class method in Ruby is the closest analogy.

The differences between the two concepts are subtle, and for the most part can initially be ignored. The essence of the difference is that, in Ruby, a class is a true object, and a class method is simply a method on that object.

11 Aug 2008, 14:13
KenA (16 posts)

Thanks Sam … it probably will take a while until I get used to Ruby language. As you sad, the difference is subtle.

You must be logged in to comment