According to the YAML documentation it's possible to pass a hash of options to the .to_yaml
method.
Currently when I pass the options as suggested by the documentation it's not working, the hash is being ignored.
irb(main):001:0> require 'yaml'
=> true
irb(main):002:0> user = { "1" => { "name" => "john", "age" => 44 } }
user.to_yaml
=> "--- \n\"1\": \n name: john\n age: 44\n"
Now, passing some options:
irb(main):014:0> user.to_yaml( :Indent => 4, :UseHeader => true, :UseVersion => true )
=> "--- \n\"1\": \n name: john\n age: 44\n"
irb(main):015:0> user.to_yaml( :Separator => "\n" )
=> "--- \n\"1\": \n name: john\n age: 44\n"
irb(main):016:0> user.to_yaml( :separator => "\n" )
=> "--- \n\"1\": \n name: john\n age: 44\n"
irb(main):017:0> RUBY_VERSION
=> "1.9.1"
As you can see, passing the options don't work. Only the defaults:
YAML::DEFAULTS
=> {:Indent=>2, :UseHeader=>false, :UseVersion=>false, :Version=>"1.0", :SortKeys=>false, :AnchorFormat=>"id%03d", :ExplicitTypes=>false, :WidthType=>"absolute", :BestWidth=>80, :UseBlock=>false, :UseFold=>false, :Encoding=>:None}
Is this a known bug? or It's currently working for anyone using Ruby 1.9.1 ?