From: Brian Candler Date: 2009-03-02T06:02:51+09:00 Subject: Re: Marshal.load does not create new instances? Ian Trudel wrote: >> Ian, I'm not sure I understand what you want. AFAIK Marshal only works >> if you have the same class definitions on both sides. Why is this a >> problem for you? > > This is actually how I use Marshal. It works fine if I have only one > version in one given Ruby program. The problem resides in loading > different files which may contain one version or another of the given > class definition. There are sometimes additional (or less) instance > variables Instance variables are not part of the class definition at all - even when you're only talking about a single version of the class. Instance variables are dynamically set within each object instance. For example: class Foo def bar @xyz = 123 end end f = Foo.new # no instance variables set at all g = Foo.new g.instance_variable_set(:@baz, 999) # only @baz is set Given this: it makes sense that serializing or deserializing an instance of Foo only takes into account what instance variables are set in that particular object, making no reference to the class definition. -- Posted via http://www.ruby-forum.com/.