From: dblack@... Date: 2006-07-26T03:39:54+09:00 Subject: Re: method self.a= and a= create different instance variables Hi -- On Wed, 26 Jul 2006, yuesefa wrote: > i try this in irb . > > irb(main):001:0> def a=(a) > irb(main):002:1> @a=a > irb(main):003:1> end > => nil > irb(main):004:0> def a > irb(main):005:1> @a > irb(main):006:1> end > => nil > irb(main):007:0> a=1 > => 1 > irb(main):008:0> a > => 1 > irb(main):009:0> self.a=2 > => 2 > irb(main):010:0> a > => 1 > irb(main):011:0> self.a > => 2 > > a and a= should be private methods of Object. so call of a or self.a > should do the same thing. but it's not. i am now confused. When you write: a = 1 Ruby parses that as a local variable assignment. In other words, methods ending in = always require that you provide an explicit receiver (in this case "self"). David -- http://www.rubypowerandlight.com => Ruby/Rails training & consultancy http://www.manning.com/black => RUBY FOR RAILS (reviewed on Slashdot, 7/12/2006!) http://dablog.rubypal.com => D[avid ]A[. ]B[lack's][ Web]log dblack@wobblini.net => me