"Ron Coutts" <rcoutts / envistatech.com> schrieb im Newsbeitrag
news:000b01c3c99e$ee53f040$9e3c010a / envistatech.com...
> Is there a library class for handling common property files that have
> the key=value syntax?  Basically all I need to do is read some
> properties from a properties file, perform succ! on some of them, and
> write the property file back to disk.  There were a couple of threads
> about properties files earlier in December that mentioned use of
> Config.rb but I'm having trouble finding documentation for this library,
> if it is one.  I'm using Ruby 1.8.0.

I made a posting some time ago, maybe that helps.  The class can work with
nested names "foo.bar.baz='hello'":

class Config
  def initialize
    @values = {}
  end

  def method_missing(sym,*args)
    s = sym.to_s.freeze

    if s[-1] == ?=
      # setter
      @values[s] = args.size == 1 ? args[0] : args
    else
      # getter
      @values[s] ||= self.class.new
    end
  end

  def load(file)
    instance_eval File.readlines(file, nil).shift
  end

  def self.load(file)
    conf = self.new
    conf.load file
    conf
  end
end

conf = Config.new

conf.load "conf.rc"
p conf

conf = Config.load "conf.rc"
p conf

Cheers

    robert