From: Luke Ivers Date: 2007-01-31T04:41:18+09:00 Subject: Re: Howto parse or eval a config-file? On Wed, 31 Jan 2007 04:30:06 +0900 "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... > > Thanks in advance for any suggestions. > > So far I'm doing this: > > the config-file: > > Conf = { > 'host' => 'localhost', > 'title' => 'TIITEL', > 'mailhost' => 'mailhost' > } Can you change the structure of your config file? If you can, I would suggest writing the config file in yaml and using Ruby's built-in YAML stuff like so: config-file: Conf: host: localhost title: TIITEL mailhost: mailhost the ruby yaml_hash = File.open( 'config.yml' ) { |file| YAML::load(file) } yaml_hash # {"Conf" => { "host" => "localhost", "title" => "TIITEL", "mailhost" => "mailhost" }} -- Luke Ivers