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" Creates a YAML::Builder that will write to the given IO.
Creates a YAML::Builder that writes to io and yields it to the block.
DEPRECATED Use .build instead
Creates a YAML::Builder that writes to io and yields it to the block.
Emits an alias to the given anchor.
Closes the builder, freeing up resources.
Starts a document, invokes the block, and then ends it.
Ends a document.
Ends a mapping.
Ends a sequence.
Ends a YAML stream.
Flushes any pending data to the underlying IO.
Starts a mapping, invokes the block, and then ends it.
By default the maximum nesting of sequences/amppings is 99.
By default the maximum nesting of sequences/amppings is 99.
Emits the scalar "< followed by an alias to the given anchor.
Emits a scalar value.
Starts a sequence, invokes the block, and the ends it.
Starts a document.
Starts a mapping.
Starts a sequence.
Starts a YAML stream.
Starts a YAML stream, invokes the block, and ends it.
Reference
Reference
Object
Object
Creates a YAML::Builder that will write to the given IO.
Creates a YAML::Builder that writes to io and yields it to the block.
After returning from the block the builder is closed.
DEPRECATED Use .build instead
Creates a YAML::Builder that writes to io and yields it to the block.
After returning from the block the builder is closed.
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" Closes the builder, freeing up resources.
Starts a document, invokes the block, and then ends it.
Ends a document.
Ends a mapping.
Ends a sequence.
Ends a YAML stream.
Starts a mapping, invokes the block, and then ends it.
By default the maximum nesting of sequences/amppings 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/amppings 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.
Starts a mapping.
Starts a sequence.
Starts a YAML stream.
Starts a YAML stream, invokes the block, and ends it.
© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/YAML/Builder.html