On 01.05.2011 02:24, I=F1aki Baz Castillo wrote:
> 2011/5/1 Phillip Gawlowski<cmdjackryan / googlemail.com>:
>> Maybe a configuration Hash is an acceptable compromise between lookup
>> speed and mutability?
>
> Humm, yes, having a HASH constant containing a hash is faster than
> accessing instance variables within a class. Just a bit, but faster :)

You never mentioned a performance problem you are trying to solve.=20
Could be that you are worrying too much about an irrelevant detail.

> So I'll use it, something like:
>
> module MyApp
>    CONFIGURATION =3D {}
> end

This might be a corner case but I would generally advice to not use=20
global variables (or constants) for this.  The reason is simply that you =

loose a lot of flexibility.  You can only ever have one active=20
configuration at a time - and you cannot change it concurrently as well.

It may be OK for a small script or application but if you make that=20
design a habit you might run into problems later.  Generally it is=20
better to provide configuration and other information from the outside=20
because that also makes testing easier.  You can pass in whatever mock=20
you want to use to test a particular feature.  If OTOH instances decide=20
themselves where to get the information from (i.e. the global variable / =

constant) you are out of luck (or you need to patch methods of the class =

under test while testing which is generally not a good idea because then =

you don't test any more what will be productive eventually).

Kind regards

	robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/