Ruby 2.5.0 リファレンスマニュアル > ライブラリ一覧 > psychライブラリ > Psych::Nodes::Nodeクラス > tag

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