123456789_123456789_123456789_123456789_123456789_

Class: Psych::Nodes::Document

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Node
Instance Chain:
self, Node, Enumerable
Inherits: Psych::Nodes::Node
Defined in: ext/psych/lib/psych/nodes/document.rb

Overview

This represents a YAML Document. This node must be a child of Stream. A Document must have one child, and that child may be one of the following:

Class Method Summary

Node - Inherited

.new

Create a new Node

Instance Attribute Summary

Node - Inherited

#children

The children of this node.

#tag

An associated tag.

Instance Method Summary

  • #root

    Returns the root node.

Node - Inherited

#each

Iterate over each node in the tree.

#to_ruby

Convert this node to Ruby.

#to_yaml
#transform
#yaml

Convert this node to YAML.

Constructor Details

.new(version = [], tag_directives = [], implicit = false) ⇒ Document

Create a new Document object.

#version is a list indicating the YAML version. tags_directives is a list of tag directive declarations #implicit is a flag indicating whether the document will be implicitly started.

Example:

This creates a YAML document object that represents a YAML 1.1 document with one tag directive, and has an implicit start:

Psych::Nodes::Document.new(
  [1,1],
  [["!", "tag:tenderlovemaking.com,2009:"]],
  true
)

See Also

See also Handler#start_document

[ GitHub ]

  
# File 'ext/psych/lib/psych/nodes/document.rb', line 44

def initialize version = [], tag_directives = [], implicit = false
  super()
  @version        = version
  @tag_directives = tag_directives
  @implicit       = implicit
  @implicit_end   = true
end

Instance Attribute Details

#implicit (rw)

Was this document implicitly created?

[ GitHub ]

  
# File 'ext/psych/lib/psych/nodes/document.rb', line 19

attr_accessor :implicit

#implicit_end (rw)

Is the end of the document implicit?

[ GitHub ]

  
# File 'ext/psych/lib/psych/nodes/document.rb', line 22

attr_accessor :implicit_end

#tag_directives (rw)

A list of tag directives for this document

[ GitHub ]

  
# File 'ext/psych/lib/psych/nodes/document.rb', line 16

attr_accessor :tag_directives

#version (rw)

The version of the YAML document

[ GitHub ]

  
# File 'ext/psych/lib/psych/nodes/document.rb', line 13

attr_accessor :version

Instance Method Details

#root

Returns the root node. A Document may only have one root node: yaml.org/spec/1.1/#id898031

[ GitHub ]

  
# File 'ext/psych/lib/psych/nodes/document.rb', line 55

def root
  children.first
end