本文介绍了Psych to_yaml选项的文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Ruby 1.9.3默认将 Psych 用于YAML.尽管完全缺少有关ruby-doc的文档,但我当时能够找到一份暗示支持indentation
选项的外部文档.这在测试中得到证实:
Ruby 1.9.3 defaults to using Psych for YAML. While the ruby-doc documentation for it is completely lacking, I was able to find one external piece of documentation that hinted that the indentation
option is supported. This was borne out in testing:
irb(main):001:0> RUBY_VERSION
#=> "1.9.3"
irb(main):002:0> require 'yaml'
#=> true
irb(main):003:0> [[[1]]].to_yaml
#=> "---\n- - - 1\n"
irb(main):009:0> [[[1]]].to_yaml indentation:9
#=> "---\n- - - 1\n"
大概支持更多选项.具体来说,我想知道如何更改换行宽度或完全禁用它.
There are presumably more options supported. Specifically, I want to know how to change the line wrap width or disable it altogether.
有哪些可用选项?
推荐答案
深入了解ruby-1.9.3-p125/ext/psych/emitter.c
的内心,我发现了三个选择:
Deep in the guts of ruby-1.9.3-p125/ext/psych/emitter.c
I found three options:
-
indentation
-级别必须小于10且大于1. -
line_width
-设置首选线宽. -
canonical
-将输出样式设置为标准格式,否则为(true/false).
indentation
- The level must be less than 10 and greater than 1.line_width
- Set the preferred line width.canonical
- Set the output style to canonical, or not (true/false).
他们工作了!
这篇关于Psych to_yaml选项的文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!