Save your file after calling YAML::dump
Not saving a yaml file after calling YAML::dump cost me about two hours the other day. Here’s an example:
# load
fnm='myyaml.yml'
h = YAML::load_file(fnm) || Hash.new
# add to hash
h[:foo]='bar'
#save# load
fnm=‘myyaml.yml’
h = YAML::load_file(fnm) || Hash.new
# add to hash
h[:foo]=‘bar’
#save
=begin
- don’t do it like this …
f = File.open(fnm, ‘w’)
YAML::dump(h, f)
#close writes the file to disk
f.close
=end
# file gets closed after block executes
File.open(fnm, ‘w’) do |out|
YAML.dump(h, out)
end
Posted in Nuby Rails, Ruby |
Trackbacks<
Use the following link to trackback from your own site:
http://plasti.cx/trackbacks?article_id=228