multiple keys for one value in yaml

2019-04-03 07:52发布

Is it possible to use different keys for the same value?

[activerecord, activemodel]: 'test'

I expect the same result as with this:

activerecord: 'test'
activemodel: 'test'

标签: arrays yaml key
1条回答
再贱就再见
2楼-- · 2019-04-03 08:31

That doesn't work because YAML allows you to specify keys of any type, so

[activerecord, activemodel]: 'test'

is a mapping with a single key, the sequence [activerecord, activemodel] whose value is 'test'.

Instead, you can use an anchor/alias:

activerecord: &my_value 'test'
activemodel: *my_value

However, there's no way of attaching both keys to the single value in one key/value pair.

查看更多
登录 后发表回答