From: uncutstone wu Date: 2006-05-19T21:47:13+09:00 Subject: Re: "Declaring" private instance variables Eli Bendersky 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. IMHO, declaration of private intance variable is a deep-rooted static way of thinking. But ruby is dynamic, in ruby, I think we need think dynamically. So, acctually, we don't need any instance variable declaration. Any instance variable can be added at the time you need. That's ruby's way. -- Posted via http://www.ruby-forum.com/.