jake kaiden wrote in post #1063123:
>   here's an example:
> https://github.com/lljk/gsWax/blob/master/brains/shared.rb

I don't think a module is the right choice. Your code relies on the 
programmer calling the "read" method before he reads or sets any value. 
If he doesn't, he'll get strange errors.

I find these implicit dependencies rather confusing. It's probably 
better to use an actual object which has the setup procedure in its 
initialize method.

Also I wouldn't use an array to store the settings, because this is 
rather error prone.

I'd probably do something like this:


#--------------------------------
class Settings

  DEFAULT_SETTINGS = {
    :foo_1 => 11,
    :foo_2 => 22,
    :foo_3 => 33
  }
  CONFIG_FILE_PATH = '<PATH>'

  def initialize
    begin
      # parse file
      @settings = '<FILE_CONTENT>'
    rescue
      @settings = DEFAULT_SETTINGS
      save!
    end
  end

  def save!
    # write settings to file
  end

  # getters and setters
  DEFAULT_SETTINGS.each_key do |config_key|
    define_method config_key do
      DEFAULT_SETTINGS[config_key]
    end
    define_method "#{config_key}=" do |val|
      DEFAULT_SETTINGS[config_key] = val
    end
  end

end
#--------------------------------

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