るりまサーチ

最速Rubyリファレンスマニュアル検索!
11件ヒット [1-11件を表示] (0.098秒)
トップページ > クエリ:l[x] > クエリ:attr[x] > クエリ:yaml_tag[x]

別のキーワード

  1. module attr
  2. net/imap attr
  3. _builtin attr
  4. rdoc attr_modifiers
  5. etc sc_thread_attr_stackaddr

ライブラリ

クラス

検索結果

Object.yaml_tag(tag) -> () (24207.0)

クラスと tag の間を関連付けます。

...YAML ドキュメントを Ruby のオブジェクトに
変換したりその逆をしたりすることができます。

@param tag 対象のクラスに関連付けるタグの文字列

=== Example
require 'psych'

class Foo
def initialize(x)
@x = x
end

attr
_reader...
...normally
p Psych.dump(Foo.new(3))
# =>
# --- !ruby/object:Foo
# x: 3

# Registers tag with class Foo
Foo.yaml_as("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)
--- !<tag:example.com,2012:foo>
x: 8
EOS
# => #<Foo:0x0000000130f48 @x=8>...