天天看點

Ruby on Rails學習拾遺(三)—使用yaml做配置

 1。将ruby對象儲存到yaml中

require 'yaml'

tree = { :name => 'ruby',

            :uses=>['script','web','testing','etc']

            }

File.open("tree.yaml","w") {|f| YAML.dump(tree,f)}

2。從yaml中讀出ruby對象

require 'YAML'

tree=YAML.load(File.open("tree.yaml"))

puts tree[:uses][2]