Like it says on the tin: you put a string into
YAML.load
and you get a data structure out; you put a data structure into
YAML.dump
and you get a string out.
Does someone can explain me how it works ?
How i can implement that ?
YAML isn’t ruby-specific, so the information on it is somewhere else: http://yaml.org/ (That landing page displays as valid YAML, by the way, and makes for a good crib sheet.)
The Wikipedia page on YAML is also worth visiting; it’s fairly comprehensive.
None of this will actually help with the Syntax of the Ruby YAML library, if that’s what you are really needing. But with a better grounding in the syntax of YAML itself, you may find that the documentation you have found makes more sense?
I'd like to point out YAML:Store, if you do not care about
handling the file operations and conversion by yourself.
It provides a simple key-value store:
require "yaml/store"
filename = "yaml_store_test.yaml"
store = YAML::Store.new(filename)
# storing some data
store.transaction do
store[:data] = [2, 3, 5, 7, 11, 13, 17, 19]
end
# reading data
data = store.transaction { store[:data] }
puts "The stored data was: #{data}"
Regards,
Marcus
···
Am 06.12.2016 um 08:18 schrieb Matthew Kerwin:
Like it says on the tin: you put a string into
YAML.load
and you get a data structure out; you put a data structure into
YAML.dump
and you get a string out.