From: Colin Bartlett Date: 2010-01-22T11:20:24+09:00 Subject: Re: Using underscores for "private" instance variables? On Wed, Jan 13, 2010 at 4:24 AM, Gregory Brown wrote: > But I agree, @_whatever is ugly and I'm not sure I will introduce it > into Prawn.   I just understand why the Rails guys did it after having > a bit of direct experience. ... > I'm about to do some major refactoring in Prawn in the near future. > I might play with these thoughts and see where they lead.   If I shake > anything loose that's worth sharing, I'll write it up on the RBP blog. Sorry for being a bit late to this thread. Date (from the 2008-01-17 version?) seems to use @__ca__ as a "hidden" cache for some values: def initialize(ajd=0, of=0, sg=ITALY) @ajd, @of, @sg = ajd, of, sg @__ca__ = {} end Are there any reasons you can't use a hash like that, or maybe use something like the code below? Admittedly, the underlying problem isn't eliminated, just reduced: one has to "agree" not to use @_ (or something similar if @_ is in use or "reserved" for future use) for a "normal" attribute. And things like @_.pa2 aren't pretty. But one thing I like about Ruby is that some things aren't forbidden, just discouraged by looking ugly and/or being difficult, so you must think carefully before using them. class ExampleClass class PrivateAtts attr_accessor :private_attribute_1, :pa2 end def initialize() ; @_ = PrivateAtts.new ; end def a_method( n ) ; @_.pa2 = n ; end def another_method() ; @_.pa2 ; end end ex = ExampleClass.new #=> #> ex.a_method(42) #=> #> ex.another_method() #=> 42