YAML Anchors Do Not Have to Be Unique
Believe it or not, according to the YAML specification, anchors do not have to be unique. In other words, an anchor name can be reused like this:
alpha: &foo # first one
repeat: me
bravo: *foo
charlie: &foo # second one
another: one
delta: *foo
Let’s say the YAML file name is a.yaml
. Here’s an example result with Ruby’s YAML library:
require 'yaml'
yaml = YAML.load_file('a.yaml', aliases: true)
p yaml['bravo'] # => {"repeat"=>"me"}
p yaml['delta'] # => {"another"=>"one"}
For what? I think if anything, it could be misleading.
See also⌗
Read other posts