From: Logan Capaldo Date: 2006-05-06T04:01:00+09:00 Subject: Re: Question on self (Newbie) On May 5, 2006, at 2:51 PM, Benjamin Pyles wrote: > I am working my way through some tutorials and books on Ruby and i am > trying to understand the various uses of the self object. For example > this code from Agile rails: > > def self.login(name,password) > # code here > end > Here, self refers to the class class NamedUser # inside here, self = NamedUser # we are defining a method that can be called like NamedUser.login or # NamedUser::login def self.login(...) ... end def try_to_login(...) # inside here self will be an instance of NamedUser instead of # NamedUser itself end end You should probably google singleton classes to really understand what's going on > def try_to_login > User.login(self.name, self.password) > end > > #Both functions belong to a class Named User > > Now I understand the self.name and self password reference the calling > object. However, I am still trying to figure out why in this > example the > function is prefixed with self. > > Ben > > -- > Posted via http://www.ruby-forum.com/. >