Brian Candler wrote in post #1083926:
>
>> What I'd really like to avoid is:
>>
>> basic_config = MySettings.new(basic_config).
>
> Why? It seems you want to create "magic" which will be very difficult
> for another programmer to follow. When you create an object, you should
> pass all the data which will be used to create state in that object, and
> you should allow the caller to decide what to do with the returned
> object.

It just looked cleaner to me! Passing in the same name as the instance
just seemed like another opportunity for a typo, and it just looked
redundant. (The Readme would show the correct usage.)

> I tried my_class.name; that returns a "Method not defined" error" (I'm
> using 1.9.3p194)

> You'll have to show the code. I use ruby 1.8, but it works fine for me.
> Notice that "name" is a method of the class, not the instance, and is
> only for Class objects because of the special-case behaviour described
> above.

Thanks for the clarification - I was trying to make it do what it can't!

>
> Of course, if you want the config to be globally accessible throughout
> your application, then you can assign it to a constant instead of a
> local variable.
>
> Config = Configs.new
> Config.load "basic_config"
> Config.load "adv_config"
> puts Config["basic_config"].inspect
>
> Or you could use a global variable, but a constant is generally
> preferred. Constants can be put into namespaces, e.g. MyApp::Config, to
> avoid clashes with other uses of Config.

I'm very leery of global constants, and I'm really nervous (literally!)
about global environment variables.

My ultimate goal was to provide a sophisticated [sic...] ValueObject
that didn't need to be told what file to parse to get its values. I was
hoping to release it as a gem, but all things considered - it certainly
looks like it's either in Ruby, or vaguely possible but really difficult
and not worth the effort. It was for a configuration system for a
Sinatra app I'm in the middle of writing; I really don't like huge,
global, configuration arrays (ala Rails), so I looked for an
alternative. SettingsLogic got me most of the way there, but the need to
specify the file, when its name was the instance name, just looked
"messy".

Oh well, thanks! I've decided that I need to rethink the problem.

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