From: ts Date: 2002-09-08T23:05:50+09:00 Subject: Re: Ruby aesthetics >>>>> "P" == Paul Brannan writes: P> 4) I'm not sure how well this maps to C. It should work, but it may not P> be the best solution. Yes, not the best Take this : P> 1) Each class has a Hash which maps object id to a table of private P> instance variables. Change it to 1) Each object has a table which maps object id of private variables to an Hash 2) look how ruby store instance variables and you have your implementation pigeon% cat b.rb #!./ruby class A def initialize @_m = [1,2] end def a p "m = #{@_m.inspect}, n = #{@_n.inspect}" end end class B < A def initialize @_m = [2,4] @_n = 6 super end def a p "m = #{@_m.inspect}, n = #{@_n.inspect}" super end def b remove_private_variable("@_n") end end b = B.new c = Marshal.load(Marshal.dump(b)) c.instance_eval do p "m = #{@_m.inspect}" a end p c.private_variables(A) p c.private_variables(B) c.b p c.private_variables(B) pigeon% pigeon% b.rb "m = nil" "m = [2, 4], n = 6" "m = [1, 2], n = nil" ["@_m"] ["@_m", "@_n"] ["@_m"] pigeon% Guy Decoux