yaml文件的设置及ruby读取yaml数据
关于yaml的介绍可以查看IBM的 yaml介绍 ,这里主要讲述yaml格式的设置及如何使用ruby读取yaml数据
yaml数据设置
--------------------------------------------
yaml的语法:
Structure通过空格来展示。Sequence里的项用“-”来代表,Map里的键值对用";"分隔,根据上面的例子,我们设置成下面的格式,并保存为: yaml.yml
data: name: John Smith age: 37 spouse: name: Jane Smith age: 25 children: - name: Jimmy Smith age: 15 - name: Jenny Smith age: 12 data1: name: watir age: 30 site: http://www.csdn.net
DATA_FILE = "D://ruby//simple//sample//lib//newFolder//yaml.yml"
problem = YAML.load(File.open(DATA_FILE))puts problem.classputs problem["data"].classputs problem["data"]["children"].classputs problem["data"]["children"][0]["name"]puts problem["data1"]["name"]puts problem["site"]
HashHashArrayJimmy Smithwatirhttp://www.csdn.net