mysql2:
host: 'localhost'
user: 'root'
require 'yaml'
file=File.expand_path('../config.yaml', __FILE__)
@config=YAML.load_file(file)
p mysql2=@config['mysql2']
# =>{"host"=>"localhost", "user"=>"root"}
p mysql2['host']
# =>localhost
#dump/yamlへの書き込み・編集
YAML.dump( @config ,
File.open(File.expand_path('../dump.yaml',
__FILE__), 'w') )
改行は”|”
d1:
aaa
bbb
ccc
d2: |
aaa
bbb
ccc
d3: >
ddd
eee
fff
出力
{“d1″=>”aaa bbb ccc”, “d2″=>”aaa\nbbb\nccc\n”, “d3″=>”ddd eee fff\n”}