From: "Damián M. González" Date: 2012-09-13T08:13:51+09:00 Subject: Marshaling classes Guys, how are you? I'm stuck thinking about how can I save the state of a class. I want to save the class variables of some classes. Do I have to require to metaprogramming for this? I mean: save those variables in an object, then dump it marshaling and then re-construct a class from that object when is loaded. I'll try to explain the situation in an example: class Dog @@quantity = 5 def self.change_quantity=(n) @@quantity = n end def self.show_quantity @@quantity end end Dog.change_quantity = 99 File.open('anyfile.mrs', 'w+') do |f| Marshal.dump(Dog, f) end Dog.change_quantity = 50 Marshal.load(File.open('anyfile.mrs')) Dog.show_quantity #=> 50 #I want to show 99 So as you can see I'm very confused. This is probably not the way to do what I want, do you have any advice for me? The objetive is to save the "state" of a class, save the values of all his class variables. Thanks. Damián. -- Posted via http://www.ruby-forum.com/.