YAML Ruby 1.9.2:停止将Syck :: MergeKey对象添加到我的哈希中

时间:2011-01-19 19:16:17

标签: ruby yaml

我正在使用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"]} 

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

1 个答案:

答案 0 :(得分:1)

尝试以下方法:

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