yaml 操做

要编写文件,须要打开YAML文件并写入句柄。

require 'yaml'
config = YAML.load_file('data.yml')
puts config['last_update'] #in my file this is set to "some data"
config['last_update'] = "other data"
File.open('data.yml','w') do |h| 
   h.write config.to_yaml
end
输出是

orcus:~ user$ ruby test.rb
some data
orcus:~ user$ cat data.yml
---
last_update: other data
相关文章
相关标签/搜索