summaryrefslogtreecommitdiff
path: root/lib/psych/nodes/node.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/psych/nodes/node.rb')
-rw-r--r--lib/psych/nodes/node.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/psych/nodes/node.rb b/lib/psych/nodes/node.rb
new file mode 100644
index 0000000000..0de768c7ac
--- /dev/null
+++ b/lib/psych/nodes/node.rb
@@ -0,0 +1,40 @@
+require 'stringio'
+
+module Psych
+ module Nodes
+ ###
+ # The base class for any Node in a YAML parse tree. This class should
+ # never be instantiated.
+ class Node
+ # The children of this node
+ attr_reader :children
+
+ # An associated tag
+ attr_reader :tag
+
+ # Create a new Psych::Nodes::Node
+ def initialize
+ @children = []
+ end
+
+ ###
+ # Convert this node to Ruby.
+ #
+ # See also Psych::Visitors::ToRuby
+ def to_ruby
+ Visitors::ToRuby.new.accept self
+ end
+ alias :transform :to_ruby
+
+ ###
+ # Convert this node to YAML.
+ #
+ # See also Psych::Visitors::Emitter
+ def to_yaml
+ io = StringIO.new
+ Visitors::Emitter.new(io).accept self
+ io.string
+ end
+ end
+ end
+end