1

I can keep below sub properties with same values. But I want to optimize.

property:
      bike: ['brake', 'wheel']
      car: ['brake', 'wheel']
      van: ['brake', 'wheel']
      bus: ['brake', 'wheel']

I want something like below, This is my thought.

Consider switch cases without break. I just wrote model. Don't think syntax.

switch(expression){
         bike:
         car:
         van:
               ['brake', 'wheel']
               break;
    }

If anything need to be added in future for case 2, i will add intermittently inside case. so that case 2 separate and can add more values like

 switch(expression){
         bike:
         car:
               ['brake', 'wheel','with or without gear']
               break;
         van:
               ['brake', 'wheel']
               break;
        }

The above is my idea. This may or may not support in yml. I want something similar to above or suggest any other best way.

Prabhu
  • 783
  • 2
  • 10
  • 35

1 Answers1

1

You can use anchors and aliases:

property:
  bike: &a [break, wheel]
  car: *a
  van: *a
  bus: *a

Note however that this represents multiple references to the same object and does not copy the given list. Depending on what you do after loading the YAML, this may or may not be what you want.

flyx
  • 35,506
  • 7
  • 89
  • 126