Builds a tree of YAML nodes.
This builder is similar to YAML::Builder
, but instead of directly emitting the output to an IO it builds a YAML document tree in memory.
All "emitting" methods support specifying a "reference" object that will be associated to the emitted object, so that when that reference object is emitted again an anchor and an alias will be created. This generates both more compact documents and allows handling recursive data structures.
Emits an alias to the given anchor.
The document this builder builds.
Emits the scalar "< followed by an alias to the given anchor.
Reference
Reference
Object
Object
Emits an alias to the given anchor.
require "yaml" nodes_builder = YAML::Nodes::Builder.new nodes_builder.mapping do nodes_builder.scalar "foo" nodes_builder.alias "key" end yaml = YAML.build do |builder| nodes_builder.document.to_yaml builder end yaml # => "---\nfoo: *key\n"
Emits the scalar "< followed by an alias to the given anchor.
See YAML Merge.
require "yaml" nodes_builder = YAML::Nodes::Builder.new nodes_builder.mapping do nodes_builder.merge "key" end yaml = YAML.build do |builder| nodes_builder.document.to_yaml builder end yaml # => "---\n<<: *key\n"
© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/YAML/Nodes/Builder.html