From: Trans Date: 2007-08-03T10:34:36+09:00 Subject: Re: ordered hashes/ yaml? On Aug 2, 11:17 am, Joel VanderWerf wrote: > Trans wrote: > > .. > > >> but to keep this as an array, it seems nasty to step thru and read > >> pairs/skip in twos thru the array: > ... > > YAML has a secondary type called an omap. It is supported in the syck > > implementation: > > That still loads as an array though: > > require 'yaml' > > h = YAML.load < section1: !omap > - link1: home > - link2: my page > - link3: logout > EOY > > p h > > __END__ > > Output: > > {"section1"=>[["link1", "home"], ["link2", "my page"], ["link3", "logout"]]} > > Maybe the !!omap is useful, but the thing it loads as doesn't seem to > have a #[] method (and it's not clear the data structure is any more > efficient than an array): > > require 'yaml' > > h = YAML.load < section1: !!omap > - link1: home > - link2: my page > - link3: logout > EOY > > p h["section1"]["link1"] # ==> undef method > > Anyone have any enlightenment...? Syck isn't 1.1 compliant (AFAIK) so you have a typo in your last example. It needs to be !omap, not !!omap. h = YAML::Omap['a',1,'b',2] => [["a", 1], ["b", 2]] h['a'] => 1 T.