YAML=Yaml Ain't Markup Language
类似于xml但更优美
require
"yaml"
str=
"Hello World!"
arr=%w{Jan Feb Mar Apr}
ha={
"this"=>
"is",
"just a"=>
"hash"}
puts str.to_yaml
puts arr.to_yaml
puts ha.to_yaml
--- Hello World!
---
- Jan
- Feb
- Mar
- Apr
---
just a: hash
this: is
---
- Jan
- Feb
- Mar
- Apr
---
just a: hash
this: is
YAML. load是to_yaml的逆方法,它接受一个字符串或流作为参数
假设如下的data.yaml文件
本文转自 fsjoy1983 51CTO博客,原文链接:http://blog.51cto.com/fsjoy/70407,如需转载请自行联系原作者