YAML
The stdlib's require "yaml" (also pulled in by big/yaml, uri/yaml and
uuid/yaml) defines the same YAML module. Loaded after cryaml it would
compile, because both load the same Any/Nodes/schema files, and its
PullParser and Builder methods would silently replace cryaml's and link
libyaml. A finished hook runs after every file is loaded, so this check
catches either order.
Class methods
Writes YAML into the given IO. A YAML::Builder is yielded to the block.
Returns the resulting String of writing YAML to the yielded YAML::Builder.
require "yaml"
string = YAML.build do |yaml|
yaml.mapping do
yaml.scalar "foo"
yaml.sequence do
yaml.scalar 1
yaml.scalar 2
end
end
end
string # => "---\nfoo:\n- 1\n- 2\n"
Returns the version of libyaml whose behavior is reproduced.
No libyaml is linked: the scanner, parser and emitter are a pure Crystal
port of libyaml 0.2.5. Code that branches on this version (for example to
account for the document end marker fix in 0.2.1) keeps working.
Deserializes a YAML document according to the core schema.
# ./foo.yml
data:
string: "foobar"
array:
- John
- Sarah
hash: {key: value}
paragraph: |
foo
bar
require "yaml"
YAML.parse(File.read("./foo.yml"))
# => {
# => "data" => {
# => "string" => "foobar",
# => "array" => ["John", "Sarah"],
# => "hash" => {"key" => "value"},
# => "paragraph" => "foo\nbar\n"
# => }