From: kturing@... (kate turing) Date: 2002-01-26T19:12:53+09:00 Subject: Re: "friend" alternative in Ruby? Mike Sassak wrote in message news:<1012006343.5969.3.camel@synecdoche>... > Could you elaborate on how you want your program to work? Thanks for the response. I am doing something very similar to your second example. I'll try to flesh out my problem a little more without dragging the application's obscure domain into the problem. FooMgr is a factory and manager for Foo objects. I'm doing this sort of this: fm = FooMgr.new resources.each do |r| f = fm.createFoo(r) end # Assume there's a FooMgr.[] method that returns a foo. # I want this to work. fm[somekey].doPublicThing # I want this to not work. fm[somekey].doPrivateThing # and i want this method to work def FooMgr.frobulate #@foos is a private @foos[somekey].doPrivateThing end Also, I'd like to enforce that Foo objects can only be created by a FooMgr. The first possibility that comes to mind is protecting Foo.initialize in the same way that I'd like to protect Foo.doPrivateThing. Looking into #send was an interesting read. But it feels a little low-level. Well, a lot. I don't think I can cleanly do exactly what I want in Ruby. Maybe I just need to get comfortable with leaving doPrivateThing public, as much as it pains me. BUT, I suspect that someone out there (who is less tainted by C++) has a Ruby-friendly way of accomplishing the same thing. Hope they speak up. k