YAML::Builder
A YAML builder generates valid YAML.
A YAML::Error is raised if attempting to generate
an invalid YAML (for example, if invoking end_sequence
without a matching start_sequence)
require "yaml"
string = YAML.build do |yaml|
yaml.mapping do
yaml.scalar "foo"
yaml.sequence do
yaml.scalar 1
yaml.scalar 2
end
yaml.scalar "bar"
yaml.mapping do
yaml.scalar "baz"
yaml.scalar "qux"
end
end
end
string # => "---\nfoo:\n- 1\n- 2\nbar:\n baz: qux\n"
Constructors
Class methods
Instance methods
Emits an alias to the given anchor.
require "yaml"
yaml = YAML.build do |builder|
builder.mapping do
builder.scalar "key"
builder.alias "example"
end
end
yaml # => "---\nkey: *example\n"
Starts a document, invokes the block, and then ends it.
If implicit_start_indicator is true, skips printing the document start
indicator (---) if this is the first document in the stream.
Starts a mapping, invokes the block, and then ends it.
By default the maximum nesting of sequences/mappings is 99. Nesting more than this will result in a YAML::Error. Changing the value of this property allows more/less nesting.
By default the maximum nesting of sequences/mappings is 99. Nesting more than this will result in a YAML::Error. Changing the value of this property allows more/less nesting.
Emits the scalar "<<" followed by an alias to the given anchor.
See YAML Merge.
require "yaml"
yaml = YAML.build do |builder|
builder.mapping do
builder.merge "development"
end
end
yaml # => "---\n<<: *development\n"
Emits a scalar value.
Starts a sequence, invokes the block, and the ends it.
Starts a document.
If implicit_start_indicator is true, skips printing the document start
indicator (---) if this is the first document in the stream.
Starts a mapping.
Starts a sequence.