I have used code which looks a little like this in an app I'm working on:
module App
module Settings
class << self
attr_accessor :console, :file
end
self.console ||= true
self.file ||= []
end
end
I decided to use this method because I like the interface, I had the idea after reading the Singleton examples from Design Patterns in Ruby.
I can then require 'app/settings'
from any file in my app and read/write the settings
p App::Settings.console
App::Settings.file << "afile.rb"
p App::Settings.file
etc...
Is this a reasonable way to keep my settings in a single file? I feel I am unnecessarily repeating myself. Any ideas for DRYing?