I am looking for a way to emit YAML files avoiding the use of aliases (mostly for simplified human readability). I think extending Psych::Visitors::Emitter
or
Psych::Visitors::Visitor
is the way to go, but I cannot actually find where Ruby decides whether to dump an anchor in full, or reference it with an alias.
I wouldn't even mind if the anchors were used repeatedly (with their &...... references), I just need to expand aliases to the full structures.
I am aware of similar questions being asked in the past, but:
- Ruby YAML write without aliases remained unanswered
- Is it possible to emit valid YAML with anchors / references disabled using Ruby or Python? gave answer for Python but not for Ruby
YAML.dump
usesYamlTree
to serialize your Ruby data to Yaml. The alias handing is done by the innerRegistrar
class and it simply emits an alias if the object in question has been seen before (based onobject_id
). – ExaltationVisitor
without aliases watch out for circular references! – Exaltation