class WorkingExample def initialize @foo = 1 @bar = 2 end def marshal_dump @foo end def marshal_load(foo) @foo = foo end end class FaultyExample < Struct.new(:foo, :bar) def initialize super(1, 2) @qux = 3 end def marshal_dump foo end def marshal_load(foo) @foo = foo end def inspect "@foo=#@foo,@bar=#@bar,@qux=#@qux" end end a = WorkingExample.new puts "WorkingExample before dump and load: #{a.inspect}" puts "WorkingExample dump #{Marshal.dump(a)}" puts "WorkingExample after dump and load: #{Marshal.load(Marshal.dump(a)).inspect}" puts b = FaultyExample.new puts "FaultyExample before dump and load: #{b.inspect}" puts "FaultyExample dump #{Marshal.dump(b)}" puts "FaultyExample after dump and load: #{Marshal.load(Marshal.dump(b)).inspect}" =begin WorkingExample before dump and load: # WorkingExample dumpU:WorkingExamplei WorkingExample after dump and load: # FaultyExample before dump and load: @foo=,@bar=,@qux=3 FaultyExample dumpIU:FaultyExamplei: @quxi FaultyExample after dump and load: @foo=1,@bar=,@qux=3 =end