Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ezhov-da/4748cffc1adad7cd5e8503d7df3f8630 to your computer and use it in GitHub Desktop.
Save ezhov-da/4748cffc1adad7cd5e8503d7df3f8630 to your computer and use it in GitHub Desktop.
Переиспользование данных

==> http://blogs.perl.org/users/tinita/2019/05/reusing-data-with-yaml-anchors-aliases-and-merge-keys.html

---
defaults: &defaults
  A: 1
  B: 2
mapping:
  << : *defaults
  A: 23
  C: 99

# same as:
mapping:
  B: 2
  A: 23
  C: 99

YAML Anchors and Aliases

---
invoice:
  billing address: &address1
    name: Santa Clause
    street: Santa Claus Lane
    city: North Pole
  shipping address: *address1
You can also use it for scalars:

---
name1: &name Larry Wall
name2: *name

YAML Merge Keys

---
- &CENTER { x: 1, y: 2 }
- &LEFT { x: 0, y: 2 }
- &BIG { r: 10 }
- &SMALL { r: 1 }

# All the following maps are equal:

- # Explicit keys
  x: 1
  y: 2
  r: 10
  label: center/big

- # Merge one map
  << : *CENTER
  r: 10
  label: center/big

- # Merge multiple maps
  << : [ *CENTER, *BIG ]
  label: center/big

- # Override
  << : [ *BIG, *LEFT, *SMALL ]
  x: 1
  label: center/big
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment