Just a quick question: Why do you want to do this?
Can’t speak for bwv549, but when I’ve wanted to do this in the past it’s
so that I can emit part of an array to the end of an existing YAML file
such that it loads as a single YAML document at a later stage.
Can’t speak for bwv549, but when I’ve wanted to do this in the past it’s
so that I can emit part of an array to the end of an existingYAMLfile
such that it loads as a singleYAMLdocument at a later stage.
Can’t speak for bwv549, but when I’ve wanted to do this in the past it’s
so that I can emit part of an array to the end of an existingYAMLfile
such that it loads as a singleYAMLdocument at a later stage.
exactly the situation.
I would stick with the “after the fact” changes to the YAML output as
tacking on YAML from one array onto the output of a different YAML
file is a very specific use-case.
My problem with those hyphens is that a yaml file without hyphens is
perfectly valid yaml (ruby yaml loads it happily) - i simply dont
understand why those hyphens are created, when the yaml file without
hyphens works perfectly nice.
perfectly valid yaml (ruby yaml loads it happily) - i simply dont
understand why those hyphens are created, when the yaml file without
hyphens works perfectly nice.
One reason for the hyphens is to allow multiple YAML documents (ie
separate objects) to be stored in a single file:
docs = [1,2,3].to_yaml + [4,5,6].to_yaml
results = []
YAML.load_documents(docs) do |doc|
results << doc
end
puts results.inspect # => “[[1,2,3], [4,5,6]]”
Notice each of the arrays is loaded separately. As for removing the
header, take a look at this post:
The author was facing the same problem. The option is {:UseHeader =>
false} but the to_yaml options aren’t currently used and don’t work,
even though at some point they probably did. It’s a deficiency in the
current release.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.