From: Stefan Lang Date: 2005-09-03T07:14:28+09:00 Subject: Re: Beginner: Options with YAML On Friday 02 September 2005 23:31, Oliver Cromm wrote: > I already use YAML to handle persistance of a queue, e.g. - one big > data structure. > > But I don't understand how to use it for many independent values, > something like Options. > > So I have a script with these settings (currently as Constants in > the script) > > SERVER = news.example.org > PORT = 100 > USER = myname > PASS = topsecret > > How do I put this in a YAML file and load it into my Ruby script? > All ways I can think of are clumsy. Or shouldn't I? One possible solution: Simply store the information in a hash in a yaml file. E.g. /home/user/.myapp.config could contain: SERVER: news.example.org PORT: 100 USER: myname PASS: topsecret Ruby code to load the settings: require 'yaml' CONFIG = YAML.load_file(File.join(ENV["HOME"], ".myapp.config")) puts "Server: #{CONFIG["SERVER"]}" puts "Server: #{CONFIG["PORT"]}" ... HTH, Stefan