123456789_123456789_123456789_123456789_123456789_

Class: Psych::Nodes::Node

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, Enumerable
Inherits: Object
Defined in: ext/psych/lib/psych/nodes/node.rb

Overview

The base class for any Node in a YAML parse tree. This class should never be instantiated.

Class Method Summary

Instance Attribute Summary

  • #children readonly

    The children of this node.

  • #tag readonly

    An associated tag.

Instance Method Summary

Constructor Details

.newNode

Create a new Node

[ GitHub ]

  
# File 'ext/psych/lib/psych/nodes/node.rb', line 21

def initialize
  @children = []
end

Instance Attribute Details

#children (readonly)

The children of this node

[ GitHub ]

  
# File 'ext/psych/lib/psych/nodes/node.rb', line 15

attr_reader :children

#tag (readonly)

An associated tag

[ GitHub ]

  
# File 'ext/psych/lib/psych/nodes/node.rb', line 18

attr_reader :tag

Instance Method Details

#each(&block)

Iterate over each node in the tree. Yields each node to block depth first.

[ GitHub ]

  
# File 'ext/psych/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 Also known as: #transform

Convert this node to Ruby.

See also ::Psych::Visitors::ToRuby

[ GitHub ]

  
# File 'ext/psych/lib/psych/nodes/node.rb', line 37

def to_ruby
  Visitors::ToRuby.create.accept(self)
end

#to_yaml(io = nil, options = {})

Alias for #yaml.

[ GitHub ]

  
# File 'ext/psych/lib/psych/nodes/node.rb', line 53

alias :to_yaml :yaml

#transform

[ GitHub ]

  
# File 'ext/psych/lib/psych/nodes/node.rb', line 40

alias :transform :to_ruby

#yaml(io = nil, options = {}) Also known as: #to_yaml

Convert this node to YAML.

See also ::Psych::Visitors::Emitter

[ GitHub ]

  
# File 'ext/psych/lib/psych/nodes/node.rb', line 46

def yaml io = nil, options = {}
  real_io = io || StringIO.new(''.encode('utf-8'))

  Visitors::Emitter.new(real_io, options).accept self
  return real_io.string unless io
  io
end