From: Austin Ziegler Date: 2003-12-06T02:56:53+09:00 Subject: Re: Attempted roadmap of future instance variables.... On Sat, 6 Dec 2003 02:41:13 +0900, Austin Ziegler wrote: > On Sat, 6 Dec 2003 01:40:42 +0900, Christoph wrote: >> Austin Ziegler wrote: >>> I rather agree with you on disliking the @_ form, but perhaps for >>> different reasons. In my module Transaction::Simple, I have named >>> most of the variables in the pattern @__foo__ (e.g., @__checkpoint__) >>> so as to reduce the chance of name collision. I'm not sure that I >>> want magic behaviour because of my choice to do this. >> The whole point of class local variables is to completely eliminate the >> possibility of name collision under subclassing. > That's fine for subclassing, but what about mix-ins? I knew I should have read Guy's response before replying ... :) As I understand it, then, because I have chosen @__checkpoint__ as the variable name, Ruby will implicitly do the right thing, right? Basically, the @_ form (class instance local) would look something like: module B def frob @_foo = "B:foo:frob" end end class A include B def initialize @_foo = "A:foo" end def foo @_foo end end x = A.new # => <#23251324: A @_foo = "A:foo"> x.foo # => "A:foo" x.frob # => "B:foo:frob" x.foo # => "A:foo" @_foo is implicitly treated as @_foo(A) or @_foo(B) depending on which method was called, right? How would this be shown in #inspect? <#234251234: A @_foo:A = "A:foo", @_foo:B = "B:foo:frob"> I'm not sure I like the @_ form in any case; it feels too "magic" in a way that "@" and "@@" don't. I think that I'm getting the way that it works, though. I also agree with Guy that this magnitude of a change for Ruby2 would break (IMO) too much if it were applied to all instance variables. -austin -- austin ziegler * austin@halostatue.ca * Toronto, ON, Canada software designer * pragmatic programmer * 2003.12.05 * 12.45.26