howto: load YAML and preserve the key order ??

Discussion in 'Ruby' started by bwv549, Oct 2, 2009.

  1. bwv549

    bwv549 Guest

    the orderedhash gem does a really nice job at allowing you to print
    yaml with ordered keys.

    # quick example to show what I'm talking about
    require 'orderedhash'
    h = OrderedHash.new
    h[3] = 8
    h[9] = 10

    h.to_yaml # will give: "---\n3: 8\n9:10" every time

    I need to be able to also read in YAML while preserving the key
    order. Any ideas on how to do this (besides using 1.9)?
    bwv549, Oct 2, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brett
    Replies:
    4
    Views:
    3,253
    Brett
    May 5, 2005
  2. Grzegorz Chrupala
    Replies:
    2
    Views:
    206
    Grzegorz Chrupala
    Jun 30, 2003
  3. Paul Battley

    YAML.dump/YAML.load bug

    Paul Battley, Aug 3, 2005, in forum: Ruby
    Replies:
    0
    Views:
    176
    Paul Battley
    Aug 3, 2005
  4. Tom Payne
    Replies:
    3
    Views:
    185
    Johannes Friestad
    Dec 14, 2005
  5. Joshua Choi

    yaml.rb and YAML "%" directives

    Joshua Choi, Jan 14, 2007, in forum: Ruby
    Replies:
    1
    Views:
    160
Loading...

Share This Page