From: David Masover Date: 2009-11-25T03:28:25+09:00 Subject: Re: Where should I put my config file, and how to load it? On Tuesday 24 November 2009 10:33:18 am Ian Bridgeman wrote: > My plan to fix this problem is to > store the config file at ~/.sweetrc, with a global config file at > /etc/sweetrc to fall back to if the home directory one isn't > available. Depending what the config file looks like, you may want to allow the global one to be overridden by the local one -- that is, something to the effect of: global_options.merge(local_options) Also, I wouldn't insist on putting anything in /etc. If users want to create /etc/sweetrc, go for it, but I'd say default back to something inside your gem, so no installation other than 'gem install' is required. Also, it's probably not an rc, since it's yaml. It's probably a .yaml or .conf. The 'rc' stands for 'run command', which implies it's an actual script -- compare to, for example, irbrc. > The second (and more ruby-ish) question I have is: How can I make sure > all my classes have access to the contents of the config file? My > classes all reside within the 'Sweet' module, and ideally I would like > to be able to do something along the lines of > > @data_directory = Sweet::Config['data_directory'] That makes sense, if you actually need that to be inside the class. You probably also want it to be possible to override by specific instances of the class, or by someone calling the class, but that might be overkill.