To_yaml and options hash


(Ara.T.Howard) #1

iccording to the docs, this should emit the version:

~/eg/ruby > ruby -r yaml -e ‘print([0,1,2].to_yaml(:UseVersion => true))’

but it simply outputs

···
  • 0
  • 1
  • 2

other options seem to be ignored too (:Separator, etc). my questions are

a) what’s up with the options hash? it does not seem to work the way the
docs imply:


puts [[ ‘Crispin’, ‘Glover’ ]].to_yaml( :Indent => 4, :UseHeader => true, :UseVersion => true )
# prints:
# — %YAML:1.0
# -
# - Crispin
# - Glover

~/eg/ruby > ruby -r yaml -e “puts [[‘Crispin’,‘Glover’]].to_yaml(:Indent=>4,:UseHeader=>true,:UseVersion=>true)”

    • Crispin
    • Glover

b) is there an option that will cause

  [ 0, 1, 2 ].to_yaml

  to be emitted as

    [ 0, 1, 2 ]

  rather than

    ---
    - 0
    - 1
    - 2

thanks for any assistance.

-a

===============================================================================

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
URL :: http://www.ngdc.noaa.gov/stp/
TRY :: for l in ruby perl;do $l -e “print “\x3a\x2d\x29\x0a””;done
===============================================================================