From: Marc-Andre Lafortune Date: 2009-12-28T11:32:32+09:00 Subject: [ruby-core:27339] [Bug #1744](Open) Error with Marshal dump/load on a delegated class. Issue #1744 has been updated by Marc-Andre Lafortune. Status changed from Closed to Open On Sun, Dec 27, 2009 at 8:19 PM, Nobuyoshi Nakada wrote: > This change has broken marshal format comatibility. Indeed. I can't think of a way to make it backward compatible, but for forward compatibility, how about the following? diff --git a/lib/delegate.rb b/lib/delegate.rb index f8a71f1..1516dac 100644 --- a/lib/delegate.rb +++ b/lib/delegate.rb @@ -184,16 +184,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])} - __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 ---------------------------------------- http://redmine.ruby-lang.org/issues/show/1744 ---------------------------------------- http://redmine.ruby-lang.org