YAML no reorder data at loading

Hi,
I want to load the following yaml content:

Yellow: 1
Blue: 2
Red: 3

And build two arrays: one for keys, that must be in this order:

['Yellow', 'Blue', 'Red'] and another for values:

[1, 2, 3]

How can I do that?

Thanks

···

--
Ranieri Barros Teixeira
Ciência da Computação - Faculdade de Computação - Universidade Federal do
Pará (UFPA)
http://rubyxchart.rubyforge.org

Alle Tuesday 04 March 2008, Ranieri Teixeira ha scritto:

Hi,
I want to load the following yaml content:

Yellow: 1
Blue: 2
Red: 3

And build two arrays: one for keys, that must be in this order:

['Yellow', 'Blue', 'Red'] and another for values:

[1, 2, 3]

How can I do that?

Thanks

As far as I can tell, you can't. This is because the notation

key: value

in YAML represents a hash, which is sorted in an arbitrary order. If you want
to keep the order, the simplest way is to replace the YAML hash with a nested
list:

- [Yellow, 1]
- [Blue, 2]
- [Red, 3]

I hope this helps

Stefano