diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/psych/handler.rb | 2 | ||||
-rw-r--r-- | lib/psych/nodes/document.rb | 9 | ||||
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 4 |
3 files changed, 13 insertions, 2 deletions
diff --git a/lib/psych/handler.rb b/lib/psych/handler.rb index 84ce4c2..f67a554 100644 --- a/lib/psych/handler.rb +++ b/lib/psych/handler.rb @@ -10,7 +10,7 @@ module Psych ### # Called when the document starts with the declared +version+, # +tag_directives+, if the document is +implicit+ - def start_document version = [], tag_directives = [], implicit = true + def start_document version, tag_directives, implicit end ### diff --git a/lib/psych/nodes/document.rb b/lib/psych/nodes/document.rb index 05eca82..0bd58b2 100644 --- a/lib/psych/nodes/document.rb +++ b/lib/psych/nodes/document.rb @@ -10,12 +10,19 @@ module Psych # Was this document implicitly created? attr_accessor :implicit - def initialize version, tag_directives, implicit + def initialize version = [], tag_directives = [], implicit = true super() @version = version @tag_directives = tag_directives @implicit = implicit end + + ### + # Returns the root node. A Document may only have one root node: + # http://yaml.org/spec/1.1/#id898031 + def root + children.first + end end end end diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index b82fc3c..a4e6152 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -14,6 +14,10 @@ module Psych visitor_for(Nodes::Mapping) do |o| Hash[*o.children.map { |c| c.accept self }] end + + visitor_for(Nodes::Document) do |o| + o.root.accept self + end end end end |