From: Ben Giddings Date: 2005-08-18T13:46:47+09:00 Subject: Re: YANQ: Nesting in YAML On Thursday 18 August 2005 00:31, basi wrote: > I think I can handle picking up keys and values here, so I'm happy with > the nesting. But now my problem is how to add extra levels of nesting > to the YAML statements, where "see" has its own substructure, something > like: > > x: > bb: > - boo > aa: > - 2 > - 3 > y: > cc: > - see > sea: > - weed > - sick > aa: > - 5 irb(main):051:0> h = {"x"=>{"aa"=>[2, 3], "bb"=>["boo"]}, "y"=>{"aa"=>[5], "cc"=>["see", {"sea" => ["weed", "sick"]}]}} => {"x"=>{"bb"=>["boo"], "aa"=>[2, 3]}, "y"=>{"cc"=>["see", {"sea"=>["weed", "sick"]}], "aa"=>[5]}} irb(main):052:0> puts h.to_yaml --- x: bb: - boo aa: - 2 - 3 y: cc: - see - sea: - weed - sick aa: - 5 => nil Did you mean "sea" has it's own substructure, i.e. the hash key "cc" points to an array with two values "see" and another hash containing one entry where the key is "sea" and the value is an array containing "weed" and "sick". If that's your goal, you were close, all you needed was the line with the dash on it before "sea:" Btw, the way I figured this out was by creating the structure in ruby in IRB, then calling "puts h.to_yaml". There are lots of braces and brackets to work through, but the error messages tend to be better. Ben