ruby读取yaml文件
假如我们有一个写好的yaml文件:
?
program:
?? id: 1
?? input: 1 2
?? output: 3
?
注意:":" 后面必须有一个空格, 层级关系用2个空格
?
?
读取方式:
require 'yaml'
problem = YAML.load(File.open("a.yml"))
puts "problem id is #{problem["program"]["id"]}"
puts "problem input is #{problem["program"]["input"]}"
puts "problem output is #{problem["program"]["output"]}"
?
结果:
problem id is 1
problem input is 1 2
problem output is 3
?