From: why the lucky stiff Date: 2005-05-15T06:44:50+09:00 Subject: Re: how to keep hash sort from YAML dave wrote: >how can I cast a YAML hash data into a ruby obj without >any auto-sort feature? >--- >2: 1 >1: 2 >3: 3 > > James is correct. Neither Ruby nor YAML allows hashes to be ordered. However, Ruby's YAML library includes an Omap type[1], which acts like the ordered dictionaries you'll find in PHP. A basic demonstration: >> require 'yaml' => true >> omap = YAML::Omap['c', 1, 'a', 2, 'b', 3] => [["c", 1], ["a", 2], ["b", 3]] >> y omap --- !omap - c: 1 - a: 2 - b: 3 As you can see, the Omap is just an array that contains hash pairs. You can use the Omap in Ruby just like a Hash. >> omap2 = YAML::load( YAML::dump( omap ) ) => [["c", 1], ["a", 2], ["b", 3]] >> omap2.each { |k,v| p [k,v] } ["c", 1] ["a", 2] ["b", 3] _why [1] http://yaml.org/type/omap.html