From 9bb41601890f6f224bdb6370476b9295a19598fc Mon Sep 17 00:00:00 2001 From: why Date: Thu, 22 May 2003 17:56:30 +0000 Subject: * lib/token.c: single- and double-quoted root-level fix. * lib/yaml.rb (YAML::object_maker): can create object attributes (such as found in Exception class) * lib/yaml/rubytypes.rb: roundtripping of Exception and subclasses. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3856 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/yaml.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'lib/yaml.rb') diff --git a/lib/yaml.rb b/lib/yaml.rb index a8bba691f0..161979bb52 100644 --- a/lib/yaml.rb +++ b/lib/yaml.rb @@ -124,13 +124,20 @@ module YAML # # Allocate blank object # - def YAML.object_maker( obj_class, val ) + def YAML.object_maker( obj_class, val, is_attr = false ) if Hash === val name = obj_class.name - o = ::Marshal.load( sprintf( "\004\006o:%c%s\000", name.length + 5, name )) - val.each_pair { |k,v| - o.instance_eval "@#{k} = v" - } + ostr = sprintf( "\004\006o:%c%s\000", name.length + 5, name ) + if is_attr + ostr[ -1, 1 ] = Marshal.dump( val ).sub( /^[^{]+\{/, '' ) + p ostr + end + o = ::Marshal.load( ostr ) + unless is_attr + val.each_pair { |k,v| + o.instance_eval "@#{k} = v" + } + end o else raise YAML::Error, "Invalid object explicitly tagged !ruby/Object: " + val.inspect -- cgit v1.2.3