I am using a YML file to store trivial data.
I can create yml:
File.open("data.yml", "w") do |yaml|
yaml.write(@some_hash.to_yaml)
end
And open yml:
path = File.expand_path(File.dirname(__FILE__))
@trivial_data = YAML.load_file("#{path}/../../../config/data.yml")
But I don’t know how to update a file. Say I want to add another row:
4:
agent_id: 332
last: Wade
first: Jason
suffix: Sr
rep_number: 2
How do I open, and update the yaml file? And is this a good idea on a production server?
Combine what you have and that’s what you should do:
You can’t add something to a file without writing to it. YaML is a serialization language, and it doesn’t make much sense to try and manipulate it directly. There is no simpler way (that I know of) that isn’t horribly prone to errors.