DEV Community

Discussion on: How to generate YAML from Ruby objects without type annotations

Collapse
 
mtancoigne profile image
Manuel Tancoigne

Hi ! Thanks for the idea, however I wonder if your method has any benefits over a quick and dirty JSON.parse(my_obj.to_json).to_yaml ?

I'm searching for something to avoid it but including a bunch of modules in my classes seems a lot of work, even if it seems really cleaner (as long a we don't forget to include the module everywhere)

Collapse
 
ayushn21 profile image
Ayush Newatia

I think the main advantage would be you'd have fine grained control over which attributes are written to the YAML representation. I believe .to_json would write out all the instance variables right? That might not always be desireable ....