问题描述:

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
相关阅读:
Top