On 5/19/06, Eli Bendersky <eliben / gmail.com> wrote:
> Hello fellow Rybuists,
>
> One thing I like about C++'s OO is the way in which all class & instance
> variables are conveniently "declared" in respective public and private
> sections. This makes the code easier to understand, since the
> declaration is a good place to comment on the variable, explaining how
> it is used.
>
> Ruby has several options regarding this, but nothing of a concensus, it
> seems. Public members can be declared with 'attr' and friends. But what
> about private memberes. For now I find it convenient to preallocate
> those in 'initialize'. What are the approaches you use ?
>
> My aim is to enhance the readability of my class. It won't affect its
> usage, just its comprehension when I return in the future trying to grok
> how it works.
>
> Eli
>
> --
> Posted via http://www.ruby-forum.com/.
>
>

Actually, the attr-family is just some metaprogramming to create new
methods.  There are no public instance variables.

Setting your variables up in initialize is fine, or when they're first
used.  Doesn't really matter.

Pat