From: Alexandru Popescu Date: 2005-08-21T18:11:27+09:00 Subject: Re: include and extend Module - Ruby Way #: Charles Steinman changed the world a bit at a time by saying on 8/21/2005 9:51 AM :# > Alexandru Popescu wrote: >> As pointed above the em#moduleMethod is failing. Being a class method I expect it to be available >> also on every instance. What I wrongly understood? > > Class methods are members of the class, not of instances of the class. > For instance, Object.new calls the class method new of Object, but you > can't do Object.new.new, because new is not an instance method. > Thanks Charles. I start to see the end tunnel light. It is the same as: [code] class ClassExample def ClassExample.do_something p "class method too" end end ClassExample.do_something # class method too cls= ClassExample.new cls.do_something # => NoMethodError [/code] Coming from the Java world, for me a class method is a (static) method available withouth a self (this) reference, but it is available/callable from any instance. (is this available in Ruby?) It seems that in Ruby the class method is a method belonging to the class ClassExample object. How can I avoid this term confusion? (at least in my head). :alex |.::the_mindstorm::.| >> Later I can read the following: >> >> [quote page=275] >> The extend method will mix a module into an object. The instance methods from the module become >> instance methods for the object. >> [/quote] >> >> Isn't this in contradiction with the first quote? > > The first quote had to do with classes; this one is talking about > instances. Telling an object "extend SomeModule" tells it to add the > methods in SomeModule to itself. In the case of a class, these will > become methods of that class. In the case of a class instance, they > will become methods of that instance. > > Does that make more sense? > > >