ruby-changes:19912
From: tenderlove <ko1@a...>
Date: Thu, 9 Jun 2011 09:10:39 +0900 (JST)
Subject: [ruby-changes:19912] tenderlove:r31958 (trunk): * ext/psych/lib/psych/visitors/to_ruby.rb: Ruby classes can be loaded
tenderlove 2011-06-09 09:06:29 +0900 (Thu, 09 Jun 2011) New Revision: 31958 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31958 Log: * ext/psych/lib/psych/visitors/to_ruby.rb: Ruby classes can be loaded from YAML files. * ext/psych/lib/psych/visitors/yaml_tree.rb: Ruby classes can be dumped to YAML files. * test/psych/test_class.rb: corresponding test. Modified files: trunk/ChangeLog trunk/ext/psych/lib/psych/visitors/to_ruby.rb trunk/ext/psych/lib/psych/visitors/yaml_tree.rb trunk/test/psych/test_class.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 31957) +++ ChangeLog (revision 31958) @@ -1,3 +1,11 @@ +Thu Jun 9 09:05:04 2011 Aaron Patterson <aaron@t...> + + * ext/psych/lib/psych/visitors/to_ruby.rb: Ruby classes can be loaded + from YAML files. + * ext/psych/lib/psych/visitors/yaml_tree.rb: Ruby classes can be + dumped to YAML files. + * test/psych/test_class.rb: corresponding test. + Wed Jun 8 21:38:57 2011 CHIKANAGA Tomoyuki <nagachika00@g...> * cont.c (root_fiber_alloc): set root fiber's status RUNNING. Index: ext/psych/lib/psych/visitors/yaml_tree.rb =================================================================== --- ext/psych/lib/psych/visitors/yaml_tree.rb (revision 31957) +++ ext/psych/lib/psych/visitors/yaml_tree.rb (revision 31958) @@ -247,7 +247,8 @@ 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 Index: ext/psych/lib/psych/visitors/to_ruby.rb =================================================================== --- ext/psych/lib/psych/visitors/to_ruby.rb (revision 31957) +++ ext/psych/lib/psych/visitors/to_ruby.rb (revision 31958) @@ -57,6 +57,8 @@ 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" Index: test/psych/test_class.rb =================================================================== --- test/psych/test_class.rb (revision 31957) +++ test/psych/test_class.rb (revision 31958) @@ -2,16 +2,18 @@ module Psych class TestClass < TestCase - def test_cycle + def test_cycle_anonymous_class assert_raises(::TypeError) do - assert_cycle(TestClass) + assert_cycle(Class.new) end end + def test_cycle + assert_cycle(TestClass) + end + def test_dump - assert_raises(::TypeError) do - Psych.dump TestClass - end + Psych.dump TestClass end end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/