当前位置: 动力学知识库 > 问答 > 编程问答 >

ruby - Can I change the number of spaces while writing yaml using YAML::dump?

问题描述:

I am writing a yaml file as follows:

File.open('output.yaml', 'w') do |f|

YAML::dump(yaml, f)

end

The content within the written file uses 2 spaces for indentation. How can I change the number of spaces? Say I want 4 spaces instead of 2, can this be done? I couldn't find any solution to do this, other than processing the whole file after writing the yaml.

网友答案:

You could pass options to Psych (psych is the default yamler):

File.open('output.yaml', 'w') do |f|
  YAML::dump(yaml, f, indentation: 4)
end
分享给朋友:
您可能感兴趣的文章:
随机阅读: