我有这样一个 YAML 文件:
Company1:
name: Something1
established: 2000
#
Company2:
name: Something2
established: 1932
读取 YAML 文件:(** 更新 **)
config = YAML.load_file('file.yaml')
config.each do |key, value|
if(key == 'name')
company_name = value
#year = config['Company1']['established']
year = config.fetch(key)['established']
end
end
** 更新 ** 现在上面的代码可以工作了,但结果显示为:
company1 => {"name" => "something1"} => {"established year" => 2000"}
如何删除 {} 和 "" ?