From: Michael Fellinger Date: 2010-04-09T14:57:37+09:00 Subject: Re: Best practice for saving settings in separate file On Thu, Apr 8, 2010 at 11:12 AM, Intransition wrote: > > > On Apr 7, 9:20 pm, Oyvind Pettersen > wrote: >> I'm currently building an application that relies on a rather large set >> of settings and paths that needs to sit in its own file. >> >> What are the best way to go about? XML? Simple strings in a text file? >> >> The settings files would be created manually, but the app will have to >> update a few integers in the files. > > Unless you have a reason not to use it, the most common practice in > Rubydom is to use YAML. > >  require 'yaml' > >  settings = YAML.load(File.new("file.yaml")) # shorter, and makes sure the fd is closed too :) require 'yaml' settings = YAML.load_file('file.yaml') # longer, but better if you want to read and write the file from # multiple processes simultaneously on unix require 'yaml/store' settings = YAML::Store.new('file.yaml') settings.transaction{|s| s['foo'] = 'bar' } settings.transaction{|s| p s['foo'] } btw, anyone wanna add JSON::Store to ruby core? -- Michael Fellinger CTO, The Rubyists, LLC