From: James Edward Gray II Date: 2007-01-31T04:36:34+09:00 Subject: Re: Howto parse or eval a config-file? On Jan 30, 2007, at 1:30 PM, ChrisKaelin wrote: > I'm currently looking for a simple way to parse a configuration file > in a ruby-script. Is eval a good way to do that? YAML seems a bit an > overkill to learn for such a small task... YAML is pretty darn simple. You be the judge... > the config-file: > > Conf = { > 'host' => 'localhost', > 'title' => 'TIITEL', > 'mailhost' => 'mailhost' > } The equivalent YAML: --- host: localhost title: TIITEL mailhost: mailhost > the eval-code: > > begin > eval File.new(configFile).read > rescue ScriptError=>e > warn("An error occurred while reading #{$configFile}: ", e) > else > $host = Conf['host'] > $title = Conf['title'] > $mailhost = Conf['mailhost'] > end And loading code: conf = File.open("path/to/conf.yaml") { |f| YAML.load(f) } James Edward Gray II