为什么 psych yaml 解释器会在 80 个字符左右添加换行符? [英] why does psych yaml interpreter add line breaks around 80 characters?
本文介绍了为什么 psych yaml 解释器会在 80 个字符左右添加换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
自 ruby 1.9.3 以来,Psych 是默认的 yaml 引擎
Psych is the default yaml engine since ruby 1.9.3
为什么,哦,为什么 psych 会在其输出中添加换行符?检查下面的示例.
Why, oh why does psych add a line break in its output? Check the example below.
ruby -v # => ruby 1.9.3p374 (2013-01-15 revision 38858) [x86_64-linux]
require 'yaml'
"this absolutely normal sentence is more than eighty characters long because it IS".to_yaml
# => "--- this absolutely normal sentence is more than eighty characters long because it
IS
...
"
YAML::ENGINE.yamler = 'syck'
"this absolutely normal sentence is more than eighty characters long because it IS".to_yaml
# => "--- this absolutely normal sentence is more than eighty characters long because it IS
"
推荐答案
您必须配置 psych 的 #to_yaml 选项.您很可能会在这里找到它:
You'll have to configure psych’s #to_yaml options. You'll most likely find it here:
ruby-1.9.3-p125/ext/psych/emitter.c
然后你可以这样做:
yaml.to_yaml(options = {:line_width => -1})
这篇关于为什么 psych yaml 解释器会在 80 个字符左右添加换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文