如何删除YAML文件顶部的'---'? [英] How to remove '---' on top of a YAML file?
问题描述
我正在修改Ruby中的YAML文件。在我写回修改的YAML之后,我看到在文件顶部添加了一个 ---
。这是如何得到补充,如何摆脱它?
YAML使用三条破折号(---)将指令与文档内容分开。如果没有指令存在,这也用于指示文档的开始。
示例:
# 1998年本垒打排名
---
- Mark McGwire
- Sammy Sosa
- Ken Griffey
#球队排名
- -
- Chicago Cubs
- St Louis红雀
所以如果你有多个文件每个YAML文件,你必须用三个破折号分隔它们。如果你只有一个文档,你可以删除/省略它(如果缺少三个破折号,我从来没有在Ruby中使用YAML的问题)。当你将对象放大时,它被添加的原因是,我猜测,翻转器是按规格书写的,并不在乎实现这样的快捷方式(当它只有一个文档时,省略三个破折号) p>
I am modifying a YAML file in Ruby. After I write back the modified YAML, I see a ---
added on top of the file. How is this getting added and how do I get rid of it?
YAML spec says:
YAML uses three dashes ("---") to separate directives from document content. This also serves to signal the start of a document if no directives are present.
Example:
# Ranking of 1998 home runs
---
- Mark McGwire
- Sammy Sosa
- Ken Griffey
# Team ranking
---
- Chicago Cubs
- St Louis Cardinals
So if you have multiple documents per YAML file, you have to separate them by three dashes. If you only have one document, you can remove/omit it (I never had a problem with YAML in ruby if three-dashes was missing). The reason why it's added when you yamlify your object is that, I guess, the dumper is written "by the spec" and doesn't care to implement such "shortcuts" (omit three-dashes when it's only one document).
这篇关于如何删除YAML文件顶部的'---'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!