From: Charles Oliver Nutter Date: 2007-12-01T00:47:09+09:00 Subject: Re: problem with 'self'. behaves different on setting and ge Cl叩udio Caseiro wrote: > Jari Williamsson wrote: >> Michal Gabrukiewicz wrote: >> > >>> THE INTERESTING THING: 'get_foo' works with 'x' and 'self.x' >> Yes, but with different result behind the scenes. 'x' is the same as >> 'x()', while 'self.x' is the same a '@x' > > > I think this is not correct. Since there are no local variable "x" in > method get_foo, bot "x" and "self.x" will send message x to self. > > If you reopen class User: > > class User > def x > "2" > end > end > > Both x and self.x in get_foo will return "2", even if @x is "1" You are correct. Both are calls to the "x" method. The only difference is that "self.x" will fail if "x" is private. - Charlie