>>>>> "M" == Michael Neumann <neumann / s-direktnet.de> writes:

M> I guess doing this in marshal.c would be only a minor change (array
M> subtraction?),  whereas to do the same in pure Ruby is much harder to
M> accomplish (but it's possible): 

[...]

M> class B < Transient
M>   @transient = :a
M>   def initialize(a, b)
M>     @a, @b = a, b
M>   end
M> end

M> b = B.new("transient!!!", 2)
M> p b
M> c = Marshal.load(Marshal.dump(b))
M> p c

   class Transient
      def transient
         obj = self.dup
         trans = self.class.class_eval "@transient"
         trans = [trans] unless trans.kind_of? Array
         trans.each do |var| 
            obj.instance_eval %q|remove_instance_variable var|
         end
         obj
      end
   end
   
   class B < Transient
      @transient = '@a'
      def initialize(a, b)
         @a, @b = a, b
      end
   end
   
   b = B.new("transient!!!", 2)
   p b
   c = Marshal.load(Marshal.dump(b.transient))
   p c



Guy Decoux