Class: Psych::Nodes::Node
- Includes:
- Enumerable
- Defined in:
- lib/psych/nodes/node.rb
Overview
The base class for any Node in a YAML parse tree. This class should never be instantiated.
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
The children of this node.
-
#tag ⇒ Object
readonly
An associated tag.
Instance Method Summary collapse
-
#each(&block) ⇒ Object
Iterate over each node in the tree.
-
#initialize ⇒ Node
constructor
Create a new Psych::Nodes::Node.
-
#to_ruby ⇒ Object
(also: #transform)
Convert this node to Ruby.
-
#yaml(io = nil, options = {}) ⇒ Object
(also: #to_yaml)
Convert this node to YAML.
Constructor Details
#initialize ⇒ Node
Create a new Psych::Nodes::Node
21 22 23 |
# File 'lib/psych/nodes/node.rb', line 21 def initialize @children = [] end |
Instance Attribute Details
#children ⇒ Object (readonly)
The children of this node
15 16 17 |
# File 'lib/psych/nodes/node.rb', line 15 def children @children end |
#tag ⇒ Object (readonly)
An associated tag
18 19 20 |
# File 'lib/psych/nodes/node.rb', line 18 def tag @tag end |
Instance Method Details
#each(&block) ⇒ Object
Iterate over each node in the tree. Yields each node to block
depth first.
28 29 30 31 |
# File 'lib/psych/nodes/node.rb', line 28 def each &block return enum_for :each unless block_given? Visitors::DepthFirst.new(block).accept self end |
#to_ruby ⇒ Object Also known as: transform
Convert this node to Ruby.
See also Psych::Visitors::ToRuby
37 38 39 |
# File 'lib/psych/nodes/node.rb', line 37 def to_ruby Visitors::ToRuby.create.accept(self) end |
#yaml(io = nil, options = {}) ⇒ Object Also known as: to_yaml
Convert this node to YAML.
See also Psych::Visitors::Emitter
46 47 48 49 50 51 52 |
# File 'lib/psych/nodes/node.rb', line 46 def yaml io = nil, = {} real_io = io || StringIO.new(''.encode('utf-8')) Visitors::Emitter.new(real_io, ).accept self return real_io.string unless io io end |