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)
I'm a freelance web developer and Rubyist. I'm the author of The Rails and Hotwire Codex (https://railsandhotwirecodex.com) and the co-host of Just A Spec.
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 ....
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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)
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 ....