diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-29 09:53:42 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-29 09:53:42 -0700 |
commit | d2bf942ac38b1b6e91116a06855a00d32b95d27b (patch) | |
tree | 0ecec2c190f7288929e0dbcfe2cc37547d5859cb /lib | |
parent | a23403e809e8ddcb6b6cccf8f0169606cd376331 (diff) | |
download | psych-d2bf942ac38b1b6e91116a06855a00d32b95d27b.zip |
sequences emit
Diffstat (limited to 'lib')
-rw-r--r-- | lib/psych/nodes/node.rb | 8 | ||||
-rw-r--r-- | lib/psych/visitors/emitter.rb | 6 |
2 files changed, 14 insertions, 0 deletions
diff --git a/lib/psych/nodes/node.rb b/lib/psych/nodes/node.rb index b5ae131..a63fc60 100644 --- a/lib/psych/nodes/node.rb +++ b/lib/psych/nodes/node.rb @@ -1,3 +1,5 @@ +require 'stringio' + module Psych module Nodes ### @@ -15,6 +17,12 @@ module Psych def to_ruby Visitors::ToRuby.new.accept self end + + def to_yaml + io = StringIO.new + Visitors::Emitter.new(io).accept self + io.string + end end end end diff --git a/lib/psych/visitors/emitter.rb b/lib/psych/visitors/emitter.rb index e2dd0be..a0ff9d9 100644 --- a/lib/psych/visitors/emitter.rb +++ b/lib/psych/visitors/emitter.rb @@ -20,6 +20,12 @@ module Psych visitor_for(Nodes::Scalar) do |o| @handler.scalar o.value, o.anchor, o.tag, o.plain, o.quoted, o.style end + + visitor_for(Nodes::Sequence) do |o| + @handler.start_sequence o.anchor, o.tag, o.implicit, o.style + o.children.each { |c| c.accept self } + @handler.end_sequence + end end end end |