From: "Damián M. González" Date: 2012-09-18T12:50:00+09:00 Subject: Re: "Anonymous classes or modules", what they are? (Marshaling) > The alternative would be to return an anonymous class with the state of > Foo at the time when f was serialized. However that's not an accurate > representation of f (it wasn't pointing to an anonymous class, it was > pointing to Foo). Moreover, we can't serialise anonymous classes anyway, > because that would mean serializing all the methods of that class. Correct me if I'm wrong: the only way that I see to save the state of a class object(like Foo in your example with his variable @count), is appeal to some methods that save the current state and then load it again when the programm start, something like this: ###################################################### class Foo @x = 1 class << self attr_accessor :x def save_state a = Object.new a.instance_eval do @x = Foo.x end File.open('Foo_state.mrs', 'w+') do |f| Marshal.dump(a, f) end end def load_state b = Marshal.load(File.open('Foo_state.mrs').read) Foo.x = b.instance_variable_get(:@x) end end end if File.exist?('Foo_state.mrs') then Foo.load_state end ######################################################## #Start the program for the first time Foo.x #=> 1 Foo.x = 5 #=> 5 Foo.save_state #=> # #Here I close the program.... #Then I start it again Foo.x #=> 5 #Was correctly saved and loaded I'll wait for your answers :) -- Posted via http://www.ruby-forum.com/.