From: dblack@... Date: 2007-06-12T19:46:03+09:00 Subject: Re: self in method name Hi -- On Tue, 12 Jun 2007, iskaldur wrote: > Is there any difference between using self in a method name, and not > using it? > For example, I've seen a lot something like > > class Foo > def self.bar > ... > end > end > > Is this the same thing as > > class Foo > def bar > ... > end > end def self.bar is just a special case of: def some_object.some_method i.e., defining a singleton method on an object (a method that exists only in the method look-up for that particular object, not for other objects of its class). Actually it's not even a special case; it's just using the current value of self as the object on which to define the method. At the top level of a class definition block, self is the class object -- in this case, Foo. A singleton method defined on a class object (such as Foo.bar) is usually referred to as a class method. In addition, class methods are special-cased a bit, in comparison with other singleton methods... but that's Lesson Two :-) David -- * Books: RAILS ROUTING (new! http://safari.awprofessional.com/9780321509246) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)