From: Carlos Date: 2004-11-21T10:20:29+09:00 Subject: Re: Inner Class Relationship [James Edward Gray II , 2004-11-21 01.22 CET] > Even if I separate the two classes, my questions remain unchanged: > What's a good way to allow one type of object to send private-ish > messages to another type of object? > > As for details: My outer class is a server. My inner class is a > connection for that server. When a connection ends, I need a way to > notify the Server object to remove it from it's maintenance list. > That's the message I'm wanting to hide from the outside world. This is a little contrived, and maybe the best option is to just use a public method. class Outer def remove x puts "removing #{x}" end private :remove def initialize @exportable_private_methods = { "remove" => lambda {|x| remove x} } end class Inner def initialize outer_methods @outer_methods = outer_methods end def run puts "running" @outer_methods["remove"].call(self) end end def run Inner.new(@exportable_private_methods).run end end Outer.new.run # => running removing #