The code
require 'yaml'
puts YAML.load("
is_something:
values: ['yes', 'no']
").to_yaml
produces
---
is_something:
values:
- "yes"
- "no"
While this is a correct yaml, it just looks ugly when you have a hash of arrays. Is there a way for me to get to_yaml
to produce the inline array version of the yaml?
An options hash can be passed to to_yaml
but how do you use it?
Edit 0: Thanks Pozsár Balázs. But, as of ruby 1.8.7 (2009-04-08 patchlevel 160), the options hash does not work as advertised. :(
irb
irb(main):001:0> require 'yaml'
=> true
irb(main):002:0> puts [[ 'Crispin', 'Glover' ]].to_yaml( :Indent => 4, :UseHeader => true, :UseVersion => true )
---
- - Crispin
- Glover
=> nil
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…