From: Don French Date: 2010-04-26T11:15:09+09:00 Subject: Re: Semi global variables On Apr 25, 9:16 pm, Intransition wrote: > On Apr 25, 9:00 pm, Don French wrote: > > > I have an application where multiple objects are created processing > > different sets of data based upon a configuration specified. Each > > object uses several other objects but those objects must use the > > configuration initially set up in the first primary object.  Each of > > the primary objects maintain their own configuration. > > > How can you have variables defined in the primary object that are > > visible to the other objects it creates? > > Well, we would need to know more to be sure. But one possibility is to > pass a reference to the primary object to all subsequent objects. That is an option but I hate to pass around that to every object. class Driver def initialize live_data_handler = Handler.new('live') test_data_handler = Handler.new('test') end def handle_command do command, data = queuemanager.wait case command when 'processlive' live_data_handler.handle(data) when 'processtest' live_data_handler.handle(data) end until command == 'quit' end end class Handler def initialize(config) @config = getconfig(config) @otherconfiginfo = other end def handle(data) lots_of_different_objects_created(data) end end this is an example of the structure. same handler code but config determines what to do and how. Don French