yaml_tag(tag) -> ()Ruby 1.9.3 から[permalink][rdoc][edit] [added by psych]-
クラスと tag の間を関連付けます。
これによって tag 付けされた YAML ドキュメントを Ruby のオブジェクトに変換したりその逆をしたりできます。
- [PARAM]
tag: - 対象のクラスに関連付けるタグの文字列
Example
require 'psych' class Foo def initialize(x) @x = x end attr_reader :x end # Dumps Ruby object normally puts Psych.dump(Foo.new(3)) # => # --- !ruby/object:Foo # x: 3 # Registers tag with class Foo Foo.yaml_tag("tag:example.com,2013:foo") # ... and dumps the object of Foo class Psych.dump(Foo.new(3), STDOUT) # => # --- !<tag:example.com,2013:foo> # x: 3 # Loads the object from the tagged YAML node p Psych.load(<<EOS, permitted_classes: [Foo]) --- !<tag:example.com,2013:foo> x: 8 EOS # => #<Foo:0x0000000130f48 @x=8> - [PARAM]