From: "David A. Black" Date: 2005-07-24T20:45:19+09:00 Subject: Re: Local Instance Methods --927295978-366620376-1122205517=:30414 Content-Type: MULTIPART/MIXED; BOUNDARY="927295978-366620376-1122205517=:30414" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --927295978-366620376-1122205517=:30414 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Sun, 24 Jul 2005, Lionel Thiry wrote: > Trans a =E9crit : >> Hi All-- >> >> I know there are plans to give Ruby private instance variables, > > Ruby will have private instance variables? What a good idea! But how > will that work? Based on what Matz has said in the past, there will be a @_ variable prefix. It's not clear whether @_var will be private, or @var will be private. Matz has said he wants to use @_var for whichever is used less often :-) (Editorial: I actually think that the ugliness of @_var is enough to make the whole thing questionable, whichever one it's used for. I'd rather see class variables eliminated, and @@var used for private instance variables. Then the net amount of punctuation would stay the same :-) Anyway... let's say @_var is private. That means that @_x in a superclass is different from @_x in a subclass: class C def set_state(x) @_x =3D x end def show_state puts @_ end end class D < C def set_hundred @_x =3D 100 end def show_hundred puts @_x end end Now if you do: d =3D D.new d.set_state(1) d.set_hundred d.show_state # 1 d.show_hundred # 100 In other words, when you use @_x in class D, you're not using the same instance variables as @_x in class C. Both "show" methods use @_x, but they're not the same @_x. David --=20 David A. Black dblack@wobblini.net --927295978-366620376-1122205517=:30414-- --927295978-366620376-1122205517=:30414--