Here’s a complete working sample illustrating the issue in YAML::Syck,
or
its documentation:
require 'yaml'
y = YAML.parse("i: b\na: sequence")
p y.kind # <-- :seq
y.children_with_index.each do |me_nil, me_key|
p me_nil # <-- nil
p me_key # <-- a Scalar
p me_key.value # <-- i, a
p y[me_key] # <-- nil
y.value[me_key] # <-- the real child object!
end
The general goal is very simple: To walk the object model, all the way
from
the root :seq down to a leaf Scalar, without ever stepping out of Syck
objects, into Hash or Array objects. The reason is because they might
have
different features, so I might lose some Syck abilities. This might just
be
impossible, so I need to know that before committing to any one
strategy.
Incidentally, the existing implementation solves the primary mismatch
between the OMap object (which I also cannot figure out how to grab
directly) and the Hash, whose keys are in an undefined sequence. The
children_with_index returns the indices in the correct order, so the
last
line y.value[key] can then get the children in the right order.
But yet children_with_index doesn’t return the children…
(If you have control over the YAML, don’t use a mapping - the spec says
order doesn’t matter for mappings. A technique I use a lot is a list of
singleton mappings:
Foo: bar
Fish: bileff
…)
Devin
Here’s a complete working sample illustrating the issue in YAML::Syck, or
its documentation:
require 'yaml'
y = YAML.parse("i: b\na: sequence")
p y.kind # <-- :seq
Another option, if you have control over the YAML – tag the mapping
with !ruby/object:OrderedHash, and go to town on an OrderedHash
implementation that enumerates its junk in order of assignment.