From: Mark Hubbart Date: 2005-05-30T02:55:52+09:00 Subject: Re: method visibility On 5/28/05, Bob Aman wrote: > More nubyness. Apologies. > > Ok, so, I have this rss feed caching system i'm working on. Ideally, > I'd like to have as little of the internal workings of the thing > visible as possible. I just want the programmer to interact with Feed > and FeedItem objects, not the caching mechanisms. > > It seems to me that I don't really want the programmer to be able to > create instances of a FeedItem manually. All FeedItems ought to be > created automatically by a Feed object. But it seems like ruby lacks > the direct equivalent of c++'s "friend", so I guess I can't give > access to the "new" class method only to Feed. The ruby way, as i would interpret it, would be to make changes to deter, but not prevent, the user-programmer from doing things you don't want, and trusting them to take the warning. For an example of this, take a look at complex.rb and rational.rb in the stdlib. Both of those classes show different ways of doing this, like replacing the #new method after aliasing it to #new2. This allows people to work naturally with the class, and follows the ruby way. And when you want to create a new version of the class in your code, call #new2, instead. cheers, Mark