Testscript. Run this to generate a /tmp/test.yml file and
populate it with the test data. This test data is stored
in @hash_data.
Here is the test.rb script:
require ‘pp’
require ‘yaml’
class YamlTesting
FILE = ‘/tmp/test.yml’
def initialize
@yaml = nil
@file = FILE
e ‘Testing from YamlTesting.rb now.’
@hash_data = { # our array test data, in hash form, please
# look at the key in it. It contains no ’ ’
‘abcdef-1.0.0’ => [
‘a’,‘b’,‘c’,‘d’,‘e’,‘f’
]
}
load_yaml # assign to @hash_data if found.
save_yaml
pp @hash_data
end
def load_yaml(i = @file)
if File.exist? i
e ‘File ‘+i+’ exists.’
@hash_data = YAML.load(File.new(i))
end
end
def save_yaml # save the yaml file somewhere. You will
# see that the key has an appended ’ ’
# in the resulting file.
e 'Saving yaml Data into '+@file
File.open(@file, ‘w+’) {|f| YAML.dump(@hash_data, f )}
end
alias e puts
end
YamlTesting.new
This will generate a yaml file like this:
abcdef-1.0.0:
- a
- b
- c
- d
- e
- f
The thing that disturbs me is that the string
"abcdef-1.0.0: " has an appended ’ '.
If you look at the datastructure in the ruby script
that generates this yaml file, the array name is:
“abcdef-1.0.0:” without appended ’ '.
It probably makes no difference, but I am still
wondering why it does so.
PS: The pasted format does not have the trailing ’ ’
but if you generate the yaml file via the ruby
script, then the result .yml file will have the
trailing ’ ’