Let’s say you have a YML file like this:
en:
thanksgiving:
turkey: 'Turkey'
stuffing: 'Stuffing'
christmas:
ham: 'Bring ham'
thanksgiving:
beer: 'lots of beer'
and you want to use ruby to basically read, consolidate and rewrite that YML like this:
en:
thanksgiving:
turkey: 'Turkey'
stuffing: 'Stuffing'
beer: 'lots of beer'
christmas:
ham: 'Bring ham'
what is the most best / most efficient way of making this happen?
You need to parse the file to get the node representation:
The
ymlvariable contains the whole structure. Example: Typing the following prints the actual entire file contentAfter inspecting the result I was able to write a safe serializer. Add a file called
config/initializers/yaml.rbNow in the rails console: