Is it possible to specify formatting options for to_yaml in ruby?

前端 未结 5 1166
说谎
说谎 2020-12-11 14:36

The code

require \'yaml\'
puts YAML.load(\"
is_something:
  values: [\'yes\', \'no\']
\").to_yaml

produces

--- 
is_somethin         


        
5条回答
  •  萌比男神i
    2020-12-11 15:28

    This ugly hack seems to do the trick...

    class Array
      def to_yaml_style
        :inline
      end
    end
    

    Browsing through ruby's source, I can't find any options I could pass to achieve the same. Default options are described in the lib/yaml/constants.rb.

提交回复
热议问题