From: Rick DeNatale Date: 2009-06-23T02:16:02+09:00 Subject: Re: Some confusion on self and the like.... On Mon, Jun 22, 2009 at 12:15 PM, Alexander Trauzzi wrote: > Hello all, > > I'm getting somewhat confused by the use of "self" when doing Ruby > programming. > > Self in other languages has typically referred to a currently executing > class, while "this" is used for the current instance. Really? All of the languages I can think of use either self, this, or _self to refer to the current instance. Some like Ruby and Smalltalk treat Classes as objects so that in a class method the current instance can be a class. Which languages use self to refer to the current class. > How does it work in Ruby, given that I've seen self used to describe > static methods AND refer to the current instance? Ruby doesn't have static methods. def self.foo end defines a singleton method on the object self, which inside a class definition is the class. > Moreover, how do I get the furthest-down-the-inheritance-chain name of > the currently running instance? self.class will get you the class of the receiver of the currently running method. Not sure what you mean by name here. Objects don't have names in general. http://talklikeaduck.denhaven2.com/2006/09/13/on-variables-values-and-objects -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale