[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby globals

lschweyer

12/5/2007 6:06:00 PM

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.
2 Answers

Ilan Berci

12/5/2007 7:25:00 PM

0

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


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

Shawn Anderson

12/11/2007 11:29:00 PM

0

Note: parts of this message were removed by the gateway to make it a legal Usenet post.

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

On Dec 5, 2007 11:25 AM, Ilan Berci <coder68@yahoo.com> wrote:

> 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
>
>
> --
> Posted via http://www.ruby-....
>
>