From db17d694ea6849b813a09856008310168c5a04ea Mon Sep 17 00:00:00 2001 From: tenderlove Date: Sat, 1 Mar 2014 02:09:53 +0000 Subject: * ext/psych/lib/psych/visitors/yaml_tree.rb: support dumping Encoding objects. * ext/psych/lib/psych/visitors/to_ruby.rb: support loading Encoding objects. * test/psych/test_encoding.rb: add test * ext/psych/lib/psych.rb: add version git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45221 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/psych/lib/psych/visitors/to_ruby.rb | 2 ++ ext/psych/lib/psych/visitors/yaml_tree.rb | 5 +++++ 2 files changed, 7 insertions(+) (limited to 'ext/psych/lib/psych/visitors') diff --git a/ext/psych/lib/psych/visitors/to_ruby.rb b/ext/psych/lib/psych/visitors/to_ruby.rb index 42b328a4bf..2f84b100d2 100644 --- a/ext/psych/lib/psych/visitors/to_ruby.rb +++ b/ext/psych/lib/psych/visitors/to_ruby.rb @@ -75,6 +75,8 @@ module Psych class_loader.date_time require 'date' @ss.parse_time(o.value).to_datetime + when '!ruby/encoding' + ::Encoding.find o.value when "!ruby/object:Complex" class_loader.complex Complex(o.value) diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb index f89fcbb8f1..ff0fcd204c 100644 --- a/ext/psych/lib/psych/visitors/yaml_tree.rb +++ b/ext/psych/lib/psych/visitors/yaml_tree.rb @@ -157,6 +157,11 @@ module Psych @emitter.end_sequence end + def visit_Encoding o + tag = "!ruby/encoding" + @emitter.scalar o.name, nil, tag, false, false, Nodes::Scalar::ANY + end + def visit_Object o tag = Psych.dump_tags[o.class] unless tag -- cgit v1.2.3