On Fri, 19 Dec 2003, Gennady wrote: > Date: Fri, 19 Dec 2003 03:13:52 +0900 > From: Gennady <gfb / tonesoft.com> > Newsgroups: comp.lang.ruby > Subject: Re: Configuration Files > <snip> > > file config.rb: > > ======== > > require 'yaml' > > config = <<-txt > > plugin: > > player: > > class: CommandPlayer > > command: mpg123 > > txt > > YAML::load(config) > > > > > > ~/eg/ruby > ruby config.rb > > /data/ruby-1.8.0//lib/ruby/1.8/yaml.rb:39:in `load': parse error on line > > 3, col 12: ` command: mpg123' (ArgumentError) > > from /data/ruby-1.8.0//lib/ruby/1.8/yaml.rb:39:in `load' > > from config.rb:8 > > > I just got it :-). However it seems like cheating ;-) -- there were no > tabs in Gavin's example. it may seem like cheating, but i spent twenty minutes debugging something just like this after advocating yaml based configs here at work and letting a real live user configure something - which immeadiately broke my software! > There are lots of issues with TABs in yaml, we all know. The common approach > is just to avoid them alltogether. I usually "untab" config files before > calling YAML::load well - i now do too. the question is, why doesn't yaml? currently i'm simply gsub'ing tabs for eight spaces and figure this _shouldn't_ breaky anything but haven't really looked into further. i posted something a while back wondering if trailing space is _ever_ required in yaml, eg if it's o.k. to do this? def parse file buf = file.respond_to?(:read) ? file.read : open(file){|f| f.read} buf.gsub! %r/\s+$/, '' YAML::load(buf) end i guess i need to rtfm... -a -- ATTN: please update your address books with address below! =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328 | STP :: http://www.ngdc.noaa.gov/stp/ | NGDC :: http://www.ngdc.noaa.gov/ | NESDIS :: http://www.nesdis.noaa.gov/ | NOAA :: http://www.noaa.gov/ | US DOC :: http://www.commerce.gov/ | | The difference between art and science is that science is what we | understand well enough to explain to a computer. | Art is everything else. | -- Donald Knuth, "Discover" | | /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done' ===============================================================================