From: Farrel Lifson Date: 2006-09-12T16:47:08+09:00 Subject: Re: newbie: yaml array of arrays On 12/09/06, allan.m.miller@gmail.com wrote: > Hello, > > I'm new to yaml, and yaml in Ruby. > > I'm trying to create a yaml file in a text editor, one part of which > will consist of an array of of arrays. The data structure I'm trying > to represent is: > > [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']] > > an array of three arrays. > > I've tried to create this yaml file in a text editor (test.cfg): > > -- a > - b > - c > -- d > - e > - f > -- g > - h > - i > > and read it in as follows > > require 'yaml' > na = open('test.cfg') { |f| YAML.load(f) } > > I get a load error: > > $ ./test.rb > /usr/lib/ruby/1.8/yaml.rb:119:in `load': parse error on line 9, col -1: > `' (ArgumentError) > from /usr/lib/ruby/1.8/yaml.rb:119:in `load' > from ./test.rb:3 > from ./test.rb:3:in `open' > from ./test.rb:3 > > The last line seems o be causing an ArgumentError. > > I'm sure my approach is completely off - how does one represent an > array of arrays in yaml, and load it into a Ruby array of arrays? > > Thanks. > > > You can use IRB to work it out in reverse... start with the ruby array and generate teh yaml from it. irb(main):004:0>require 'yaml' =>true irb(main):005:0> puts [['a','b','c'],['d','e','f'],['g','h','i']].to_yaml --- - - a - b - c - - d - e - f - - g - h - i =>nil Farrel