From: "James F.Hranicky" Date: 2002-09-13T00:21:17+09:00 Subject: Re: private variables --=.JgyI?zXRbHO.Rr Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 12 Sep 2002 23:17:03 +0900 Dave Thomas wrote: > "Christoph" writes: > > > which means one more set of scoping rules to keep mind? (Probably > > not, but even the prospect makes me shudder;-) > > Actually, that raises an interesting point. > > If we're (somewhat unfortunately, imo) using '_' to denote 'localized', > then should we be using more orthogonally? > > @_a - localized instance variable > > > _a - localized block variable, > > _a = 1 > > 10.times {|_a| puts _a} > > puts _a # => 1 > > > If we're going down this route (and I'm wondering if I think we > should), then we can at least make us of the options. How about an attr_private directive? class Foo attr_accessor :a, :b; attr_private :c end class Bar < Foo attr_accessor :c end x = Bar.new p x.c # Actually using Bar::c, not Foo::c Seems syntactically cleaner to me. Of course, throwing back to the local block variable thing, how about - default to all local, indicate lookups in previous scopes with :: foo.each { |x,::y| a = x # local a modified, value of local x ::b = y # global b now value of global y } ? ---------------------------------------------------------------------- | Jim Hranicky, Senior SysAdmin UF/CISE Department | | E314D CSE Building Phone (352) 392-1499 | | jfh@cise.ufl.edu http://www.cise.ufl.edu/~jfh | ---------------------------------------------------------------------- "Given a choice between a complex, difficult-to-understand, disconcerting explanation and a simplistic, comforting one, many prefer simplistic comfort if it's remotely plausible, especially if it involves blaming someone else for their problems." -- Bob Lewis, _Infoworld_ --=.JgyI?zXRbHO.Rr Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (SunOS) iD8DBQE9gLDjqJn1asfI5oQRAmJAAJ9+fMII482maI71J4l2lIjuvZcCdQCfeqbR OLJ3gzvDx1FM8n3uYtK2Jwo= =Nmg3 -----END PGP SIGNATURE----- --=.JgyI?zXRbHO.Rr--