From 6696baf6c238b7cd032fe02482ce0435349901b8 Mon Sep 17 00:00:00 2001 From: marcandre Date: Tue, 29 Dec 2009 01:56:55 +0000 Subject: [PATCH] * lib/delegate.rb (marshal_dump/load): Provide forward compatibility [ruby-core:24211] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@26194 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/delegate.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/delegate.rb b/lib/delegate.rb index e709b72209..9ed1409ba0 100644 --- a/lib/delegate.rb +++ b/lib/delegate.rb @@ -179,17 +179,21 @@ class Delegator # Serialization support for the object returned by \_\_getobj\_\_. def marshal_dump [ + :__v2__, instance_variables, instance_variables.map{|var| instance_variable_get(var)}, __getobj__ ] end # Reinitializes delegation from a serialized object. - def marshal_load(obj) - vars, values, obj = obj - vars.each_with_index{|var, i| instance_variable_set(var, values[i])} - initialize_methods(obj) - __setobj__(obj) + def marshal_load(data) + version, vars, values, obj = data + if version == :__v2__ + vars.each_with_index{|var, i| instance_variable_set(var, values[i])} + __setobj__(obj) + else + __setobj__(data) + end end end