ajsie ajsie - 1 month ago 7x
YAML Question

Reuse a block of code in YAML

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?

Company: &company Foo
Item: &item 123

Company: *company
Item: *item
Price: 3000

# sequencer protocols for Laser eye surgery
- step:  &id001                  # defines anchor label &id001
    instrument:      Lasik 2000
    pulseEnergy:     5.4
    pulseDuration:   12
    repetition:      1000
    spotSize:        1mm

- step: &id002
    instrument:      Lasik 2000
    pulseEnergy:     5.0
    pulseDuration:   10
    repetition:      500
    spotSize:        2mm

- step: *id001                   # refers to the first step (with anchor &id001)
- step: *id002                   # refers to the second step
- step: *id001
- step: *id002

sample from wikipedia