我在某种程度上理解,但是我还没有看到一个例子,它所带来的问题比解答更多。
http://rhnh.net/2011/01/31/yaml-tutorial
# Set.new([1,2]).to_yaml
--- !ruby/object:Set
hash:
1: true
2: true
我理解我们正在声明一个Set标签,但是我不知道后续的哈希映射和它有什么关系。我们是否在声明模式?可以有人展示一下多个标签声明的例子吗?
我已阅读规范:http://yaml.org/spec/1.2/spec.html#id2761292
%TAG ! tag:clarkevans.com,2002:
这是在声明一个模式吗?解析器还需要做些什么才能成功解析文件?需要一种模式文件吗?
http://www.yaml.org/refcard.html
Tag property: # Usually unspecified.
none : Unspecified tag (automatically resolved by application).
'!' : Non-specific tag (by default, "!!map"/"!!seq"/"!!str").
'!foo' : Primary (by convention, means a local "!foo" tag).
'!!foo' : Secondary (by convention, means "tag:yaml.org,2002:foo").
'!h!foo': Requires "%TAG !h! <prefix>" (and then means "<prefix>foo").
'!<foo>': Verbatim tag (always means "foo").
为什么需要主标签和次标签?为什么次标签要引用URI?这样做解决了什么问题?
看到很多“它们是什么”的描述,却没有说明“它们为什么存在”或“它们用于什么”。
#Set.new([1,2]).to_yaml
实际上是一条注释-它是一个Ruby语句,将输出其下方的YAML。 - Alex