13aal 13aal - 6 months ago 10
Ruby Question

Giving a YAML file more than one key, while only using one value for the keys

I have an issue where I need to make a yaml file that will contain the following keys:


ETA SOL VETS EMC


From these keys I need one value that will be an email address all four of the keys are the same email address, is it possible to make a yaml file with more then one key, and only one value..?

For example:

agencies:
- ETA
- SOL
- VETS
- EMC
advocate_email: "example@example.com" #<= Give these four the same value
- some
- other
- ones
advocate_email: "example1@example1.com" #<= Give three another value.. So one and so forth

Answer

** UPDATE ** I think you have multiple emails and each group has a longer list.

group1:
  email: me@email.com
  list:
    - ETA
    = SOL
    - VETS
group2:
  email: me2@email.com
  list:
    - ONE
    - TWO
    - THREE

** END UPDATE **

If I understand correctly and that you want the same email:

email: &email me@email.com

emails:
  ETA: *email
  SOL: *email
  VETS: *email

Output:

pry(main)> YAML.load(File.read('foo.yml'))
=> {"email"=>"me@email.com", "emails"=>{"ETA"=>"me@email.com", "SOL"=>"me@email.com", "VETS"=>"me@email.com"}}