From: Albert Wagner Date: 2002-11-01T02:54:14+09:00 Subject: Re: method-call style (was Re: Snippet: Tiny Featureless Ruby Web Server) On Thursday 31 October 2002 10:42 am, Nat Pryce wrote: > > Of course they give different results: @thing is a state variable, stuff= > > modifies the state variable, and stuff is simply an algorithm that > > happens to utilize the state variable. Assuming that stuff and @thing > > are synonymous is what is wrong. > > Exactly my point! And it looks like a trivial point when illustrated > with the code above. However, the point is as valid, although much less > obvious to many programmers, when illustrated with David Black's > original code, which was a direct assignment to and return from an > instance variable. And the point is even less obvious when the accessor > functions have the same name as the instance variable: > > def stuff > @stuff > end > > def stuff=( new_stuff ) > @stuff = new_stuff > end > > Cheers, > Nat. Hi, Nat. I guess I misunderstood the comment: "Definitely use self.stuff to avoid breaking encapsulation." I am still unsure of what is meant here. I can only see using self.stuff to differentiate between a var named stuff and a method named stuff. But, personally, I would never use the same name for both. -- "I invented the term Object-Oriented, and I can tell you I did not have C++ in mind." -Alan Kay