Alex Rivera | Logout

Reuse a hash in YAML

Asked 2011-12-11T18:04:38.557
127

I want to reuse a hash in YAML:

Defaults: &defaults
  Company: Foo
  Item: 123

Computer: *defaults
  Price: 3000

However, this generates an error.

Is the only way to anchor each field value separately like this?

Defaults:
  Company: &company Foo
  Item: &item 123

Computer:
  Company: *company
  Item: *item
  Price: 3000
Edit
Report

1 Answer

368

Try reusing a full group by importing it:

Defaults: &defaults
  Company: foo
  Item: 123

Computer:
  <<: *defaults
  Price: 3000

Documentation: http://yaml.org/type/merge.html

answered 2012-02-08T16:19:03.493

Your Answer