From e28d3dbca422250d291e98d39d9c4ef2317e3b8c Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 8 Jun 2011 17:06:46 -0700 Subject: ruby classes can round trip --- lib/psych/visitors/to_ruby.rb | 2 ++ lib/psych/visitors/yaml_tree.rb | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index f8b1585..cb0afd2 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -57,6 +57,8 @@ module Psych Complex(o.value) when "!ruby/object:Rational" Rational(o.value) + when "!ruby/class" + resolve_class o.value when "tag:yaml.org,2002:float", "!float" Float(@ss.tokenize(o.value)) when "!ruby/regexp" diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb index 6f90377..de35c76 100644 --- a/lib/psych/visitors/yaml_tree.rb +++ b/lib/psych/visitors/yaml_tree.rb @@ -247,7 +247,8 @@ module Psych end def visit_Class o - raise TypeError, "can't dump anonymous class #{o.class}" + raise TypeError, "can't dump anonymous class: #{o}" unless o.name + @emitter.scalar o.name, nil, '!ruby/class', false, false, Nodes::Scalar::SINGLE_QUOTED end def visit_Range o -- cgit v1.2.3