The code
require \'yaml\'
puts YAML.load(\"
is_something:
values: [\'yes\', \'no\']
\").to_yaml
produces
---
is_somethin
Just another hack to specify the output style, but this one allows to customize it per specific object, instead of globally (e.g. for all arrays).
https://gist.github.com/jirutka/31b1a61162e41d5064fc
Simple example:
class Movie
attr_accessor :genres, :actors
# method called by psych to render YAML
def encode_with(coder)
# render array inline (flow style)
coder['genres'] = StyledYAML.inline(genres) if genres
# render in default style (block)
coder['actors'] = actors if actors
end
end