るりまサーチ (Ruby 3.3)

最速Rubyリファレンスマニュアル検索!
2件ヒット [1-2件を表示] (0.362秒)

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin []
  4. _builtin to_s
  5. _builtin each

種類

クラス

検索結果

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

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

...g 対象のクラスに関連付けるタグの文字列

=== Example
require 'psych'

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

attr_reader :x
end

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

# Registers tag...
...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:0x00...

Psych::Parser (97.0)

YAML のパーサ。

...ュメントを
別のフォーマット変換したりします。
Psych
::Emitter を使うとパースしたドキュメントを元通りに出力
することもできます。

Psych
::Parser が生成するイベントは Psych::Handler
を見てください。

以下の例では YAML ドキ...
...or detecting scalar values
class ScalarHandler < Psych::Handler
def scalar value, anchor, tag, plain, quoted, style
puts value
end
end

parser = Psych::Parser.new(ScalarHandler.new)
parser.parse(yaml_document)

次の例は Psych::Emitter にパースの結果を戻していま...
...力をパース→YAMLフォーマットで STDERR に出力
という流れになっています。

parser = Psych::Parser.new(Psych::Emitter.new($stderr))
parser.parse($stdin)

Psych
::Parser と Psych::TreeBuilder を組み合わせると
YAML の AST を構築することができます。...