From: "Jesús Gabriel y Galán" Date: 2009-11-14T07:02:20+09:00 Subject: Re: Module with a class? On Fri, Nov 13, 2009 at 9:30 PM, Judson Lester wrote: > On Fri, Nov 13, 2009 at 10:48 AM, Matt Brooks wrote: > >> I may need to reexplain it, but basically want classes in different >> files, but want the other classes to have access to 1 core files' >> objects instance variables and methods, since this core object will be >> creating the other objects of the other classes in the other files.... >> >> > Some example code would help a lot.  File boudaries notwithstanding it > sounds like you have something like: > > class Hello >  def say >    puts "Hello" >  end > end > > class Core >  def initialize >    @hello=nil >  end > >  attr_reader :hello > >  def add_hello_widget >    @hello= Hello.new >  end > end > > core = Core.new > core.add_hello_widget > core.hello.say  #=> "Hello" > > Something like that?  If not, what's missing? If I understood correctly, he wants objects of class Hello to call methods on the instance of Core which created them. Something like (untested): class Hello def initialize core @core = core end def say puts "hello: #{@core.msg}" end end class Core def initialize msg @msg = msg @hello=nil end attr_reader :hello, :msg def add_hello_widget @hello= Hello.new self # pass the instance of core to the hello instance end end core = Core.new "i'm core" core.add_hello_widget core.hello.say #=> "hello: i'm core" Hope this helps, Jesus.