このマニュアルは既にメンテナンスが終了したバージョンの Ruby を対象としています。 最新版のマニュアルへ

Ruby 2.0.0 リファレンスマニュアル

instance method Psych::Nodes::Node#tag

tag -> String | nil[permalink][rdoc]

ノードに付加されたタグを返します。

タグが付加されていない場合は nil を返します。

ast = Psych.parse(<<EOS)
----
- !!str a
- b
EOS

p ast.root.children[0].value  # => "a"
p ast.root.children[0].tag    # => "tag:yaml.org,2002:str"

p ast.root.children[1].value  # => "b"
p ast.root.children[1].tag    # => nil