From a4dbc2ea1020a0a393a0134cc900397a895a88e7 Mon Sep 17 00:00:00 2001 From: tenderlove Date: Wed, 31 Mar 2010 21:09:58 +0000 Subject: * ext/psych/lib/psych.rb: Syck api compatibility [ruby-core:29157] * ext/psych/lib/psych/nodes/node.rb: ditto * test/psych/test_psych.rb: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27134 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/psych/lib/psych.rb | 9 +++++++-- ext/psych/lib/psych/nodes/node.rb | 10 ++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'ext') diff --git a/ext/psych/lib/psych.rb b/ext/psych/lib/psych.rb index 59307e3d99..9b4b215b67 100644 --- a/ext/psych/lib/psych.rb +++ b/ext/psych/lib/psych.rb @@ -153,10 +153,15 @@ module Psych # Example: # # Psych.dump(['a', 'b']) # => "---\n- a\n- b\n" - def self.dump o, options = {} + def self.dump o, io = nil, options = {} + if Hash === io + options = io + io = nil + end + visitor = Psych::Visitors::YAMLTree.new options visitor << o - visitor.tree.to_yaml + visitor.tree.to_yaml io end ### diff --git a/ext/psych/lib/psych/nodes/node.rb b/ext/psych/lib/psych/nodes/node.rb index 0de768c7ac..3ab9acae43 100644 --- a/ext/psych/lib/psych/nodes/node.rb +++ b/ext/psych/lib/psych/nodes/node.rb @@ -30,10 +30,12 @@ module Psych # Convert this node to YAML. # # See also Psych::Visitors::Emitter - def to_yaml - io = StringIO.new - Visitors::Emitter.new(io).accept self - io.string + def to_yaml io = nil + real_io = io || StringIO.new + + Visitors::Emitter.new(real_io).accept self + return real_io.string unless io + io end end end -- cgit v1.2.3