【问题标题】:YAML Ruby 1.9.2: Stop adding Syck::MergeKey objects into my hashesYAML Ruby 1.9.2:停止将 Syck::MergeKey 对象添加到我的哈希中
【发布时间】:2011-01-19 19:16:17
【问题描述】:

我正在使用 Ruby 1.9.2 和 Rails 3.0.1,我遇到了一个奇怪的 YAML 问题。这是我的 YAML 文件:

#config/tags_constants.yml
:main_ingredients: &ingredients
  - Beans 
  - Beef 
  - Cheese 
  - Chocolate 
  - Dairy 
  - Eggs 
  - Fish 
  - Fruits 
  - Game 
  - Lamb 
  - Nuts 
  - Pasta 
  - Pork 
  - Poultry 
  - Rice/Grains 
  - Shellfish 
  - Tofu/Soy 
  - Vegetables 

:excluded_ingredients:
<<: *ingredients

这是我在控制台中看到的:

> hash = YAML.load(File.open("config/tags_constants.yml"))
> hash["excluded_ingredients"]
 => {#<Syck::MergeKey:0x00000101b379d0>=>["Beans", "Beef", "Cheese", "Chocolate", "Dairy", "Eggs", "Fish", "Fruits", "Game", "Lamb", "Nuts", "Pasta", "Pork", "Poultry", "Rice/Grains", "Shellfish", "Tofu/Soy"]} 

如何让 YAML 合并值而不添加这些奇怪的 Syck::MergeKey 对象?

【问题讨论】:

  • 如果您之前问题的答案已经解决了您的问题,您可能需要通过单击它们旁边的勾号来“接受”它们。

标签: ruby yaml


【解决方案1】:

尝试以下方法:

client: &client
  - Brad
  - Angelina
:development: 
  :requests: 1
  :client: 
    :session: "something"
    :paths: 
      *client

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-08
    • 2017-09-20
    • 2012-08-07
    • 2011-02-17
    • 2021-09-15
    • 2018-08-22
    相关资源
    最近更新 更多