如何删除 YAML 文件顶部的“---"? [英] How to remove '---' on top of a YAML file?

查看:20
本文介绍了如何删除 YAML 文件顶部的“---"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 Ruby 修改一个 YAML 文件.在我写回修改后的 YAML 后,我看到在文件顶部添加了一个 ---.这是如何添加的,我该如何摆脱它?

解决方案

YAML 规范说:

<块引用>

YAML 使用三个破折号(---")将指令与文档内容分开.如果不存在指令,这也用于表示文档的开始.

示例:

# 1998 年本垒打排名---- 马克麦奎尔- 萨米索萨——肯·格里菲# 团队排名---- 芝加哥小熊队- 圣路易斯红雀队

因此,如果每个 YAML 文件有多个文档,则必须用三个破折号将它们分开.如果您只有一个文档,则可以删除/省略它(如果缺少三个破折号,我在 ruby​​ 中从未遇到过 YAML 问题).当你对你的对象进行 yamlify 时添加它的原因是,我猜,转储程序是由规范"编写的,并不关心实现这样的快捷方式"(当它只有一个文档时省略三个破折号).

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆