Nit Khair wrote:
> Small question. The app is not separate programs loaded from the command 
> line. The main menu loads, then other classes available in other files 
> are required and instantiated.
> 
> So there are many separate files, but one ruby interpreter. Will 
> "$config["XXX"] work through all the programs ?

Yes. Your apps will be written in such a way that they're somewhat tied 
to the global data structure, but if there's no intention of re-using 
the component objects elsewhere that's no problem.

Otherwise you could do something like this:

[config file]
  thing1:
    x: abc
    y: def
  thing2:
    a: xyz
    b: tuv

[library]
  class Thing1
    def initialize(params)
      x = params["x"]
      y = params["y"]
    end
  end

[initialisation]
  $config = YAML.load("/etc/myapp.conf")
  o1 = Thing1.new($config["thing1"])

You can of course put object instances in global variables too. They can 
be named:

  $logger ||= Logger.new(...)

Or you can use the "object locator" pattern, which is a fancy way of 
saying an object containing the other objects.

  $locator ||= {}
  $locator[:logger] ||= Logger.new(...)

Taking this one step further you get to dep inj, since creation of each 
object can make use of other objects in the container.

> Will look into dep inj soon - thanks for the tip.

I see you already found the page. I had a copy of the code lying around, 
so I'll attach it to this message.

Personally I'd load the $config and then use depinj to set up the 
individual objects. This code is very easy to re-use, since any objects 
in the container which you don't access don't get created.

Attachments:
http://www.ruby-forum.com/attachment/2790/depinj.rb

-- 
Posted via http://www.ruby-forum.com/.