From: Chris Moore Date: 2001-08-15T00:52:51+09:00 Subject: [ruby-talk:19699] class methods and optimizing Does anyone know what class methods are as opposed to instance methods? Are they for optimizing? when would I use them?I have looked at a couple manuals that tell you how to do them: def classname.method but none seem to explain the why and when. And this leads to my second question. In terms of memory usage and speed, is it better to extend the existing classes (when possible) or to build your own, or to just make a subclass? e.g. If I program a deck routine for a card game I can just add shuffle, play etc. routines to class Array. Now the computer isn't holding an extra class definition in memory, but ALL arrays (not decks) are also extended. If I make my own class/subclass, not all of the arrays are extended but there is another class definition in memory... The first question is related to the second as well... what difference does it make if they are class methods... Programming Ruby says that they are methods that stay with the class in memory and not with the objects... does that mean that extending Array but making them class ones mean that all Arrays before that don't get those methods or what? hmmm..... The last one here is easy... I remember from somewhere that self is the default object. So can I remove it from class definitions completely and it's just there to save confusion while reading? (Sorry brain on the fritz....*bang* *bang*....) My deck array extention (for those interested) is at http://www.rubycookbook.org/showrecipe.rb?recipeID=115 -- ------------------ Chris Moore As a dog returns to it's vomit so a fool totheir folly -God