YAML 文件中的哈希? [英] Hash inside YAML file?

查看:45
本文介绍了YAML 文件中的哈希?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我使用以下命令解析的 YAML 文件中包含一个哈希和列表:

I want to include a hash and list inside a YAML file that I'm parsing with the following command:

APP_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/config.yml")

我的 YAML 文件如下所示:

My YAML file looks like this:

feeds: [{:url => 'http://www.google.com', :label => 'default'}]

但这似乎不起作用.我将如何实现这样的目标?

But this doesn't seem to work. How would I go about achieving such a thing?

谢谢,尤瓦尔

对不起,伙计们.我仍然不清楚如何做到这一点,我怀疑部分原因是我的措辞有些含糊.我在此处问了一个措辞更好、更广泛的问题.谢谢!

Sorry, guys. I'm still unclear about how to do this and I suspect it is in part due to my somewhat vague phrasing. I asked a better-phrased, more broad question here. Thank you!

推荐答案

你可以这样标记

feeds:
 - 
  url: 'http://www.google.com'
  label: 'default'

注意这里的间距很重要."-" 必须缩进一个空格(不是制表符),后跟一个空格.和 url &label 必须缩进两个空格(也不是制表符).

Note the spacing is important here. "-" must be indented by a single space (not a tab), and followed by a single space. And url & label must be indented by two spaces (not tabs either).

此外,这可能会有所帮助:http://www.yaml.org/YAML_for_ruby.html

Additionally this might be helpful: http://www.yaml.org/YAML_for_ruby.html

这篇关于YAML 文件中的哈希?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆