1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/delegate.rb (marshal_dump/load): Provide forward compatibility [ruby-core:24211]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
marcandre 2009-12-29 01:56:55 +00:00
parent cff7d0c80e
commit 92ab16fac6

View file

@ -184,16 +184,21 @@ class Delegator
# Serialization support for the object returned by \_\_getobj\_\_. # Serialization support for the object returned by \_\_getobj\_\_.
def marshal_dump def marshal_dump
[ [
:__v2__,
instance_variables, instance_variables,
instance_variables.map{|var| instance_variable_get(var)}, instance_variables.map{|var| instance_variable_get(var)},
__getobj__ __getobj__
] ]
end end
# Reinitializes delegation from a serialized object. # Reinitializes delegation from a serialized object.
def marshal_load(obj) def marshal_load(data)
vars, values, obj = obj version, vars, values, obj = data
vars.each_with_index{|var, i| instance_variable_set(var, values[i])} if version == :__v2__
__setobj__(obj) vars.each_with_index{|var, i| instance_variable_set(var, values[i])}
__setobj__(obj)
else
__setobj__(data)
end
end end
# Clone support for the object returned by \_\_getobj\_\_. # Clone support for the object returned by \_\_getobj\_\_.