Ruby globals

I am have a moderate knowledge of Ruby and OO programming.
In my current Ruby program I have an include file that just contains
my global variables. Now, I read some where, that I should avoid
using
globals as they can be easily trampled on.
I use the globals to hold information I’ve read from an XML file at
startup
time that contains various options for my program and are easily
referenced
by my procedures.
If I’m to avoid globals, then where would be a good place to keep
these
options? Should I create an Option class and pass it around?

Thanks for any tips.

unknown wrote:

by my procedures.
If I’m to avoid globals, then where would be a good place to keep
these
options? Should I create an Option class and pass it around?

Thanks for any tips.

Research the GOF singleton pattern… it is used extensively to solve the
requirement you currently have

hth

ilan

I would also look at how hard it would be to pass around some kind of
Config
object to a few parts of the app.

Careful consideration should be given to the use of Singletons as they
tend
to hinder testing.

my .02
/Shawn

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs