YAML中的多级嵌套

我正在尝试使用YAML创建应用程序中使用的所有存储过程的列表以及从中调用它们的位置。 我设想了类似下面的东西,但我认为YAML不允许多级嵌套。

access_log: stored_proc: getsomething uses: usedin: some->bread->crumb usedin: something else here stored_proc: anothersp uses: usedin: blahblah reporting: stored_proc: reportingsp uses: usedin: breadcrumb 

有没有办法在YAML中做到这一点,如果没有,还有什么其他选择?

这正是我在YAML中使用嵌套级别来获取perl脚本的配置文件的方法。 对于如何在Ruby中处理所需结构, 本YAML教程可能是一个很好的参考。

我认为你的问题是尝试混合类型。 我建议修改如下:

 reporting: stored_procs: reportingsp uses: usedin: breadcrumb secondProc uses: usedin: something_else 

正如@Ilion所指出的,你不能拥有指向字符串和对象的属性; 你需要一个数组,或给你的stored_proc名称一个标签。 此外,当您真正想要的是一个数组时,使用相同的名称继续在键上运行。 这是一个简单的例子,certificate它有效:

 MY_YAML = " access_log: - name: getsomething uses: - some->bread - something else here - name: anothersp uses: - blahblah" require 'yaml' require 'pp' pp YAML.load(MY_YAML) #=> {"access_log"=>[ #=> {"name"=>"get something", "uses"=>["some->bread", "something else here"]}, #=> {"name"=>"anothersp", "uses"=>["blahblah"]} #=> ]} 
 --- access_log: - stored_proc: getsomething - uses: - usedin: some->bread->crumb - usedin: something else here - stored_proc: anothersp - uses: - usedin: blahblah reporting: - stored_proc: reportingsp - uses: - usedin: breadcrumb