From: "Damián M. González" Date: 2012-09-17T00:31:33+09:00 Subject: Re: "Anonymous classes or modules", what are? (Marshaling) Peter Zotov wrote in post #1076193: > I'm not sure as what was mentioned in the book as I don't have it, but > I guess > that it was only talking about _instances_ of anonymous classes. You > don't often > need to serialize classes themselves, and, as I've mentioned, you > cannot serialize > code, be that closures or methods. Objects with singleton methods will > have those > singleton methods lost: > irb > obj = Object.new > => # > irb > def obj.bark > irb > puts "Howl!" > irb > end > => nil > irb > serial = Marshal.dump(obj) > TypeError: singleton can't be dumped > from (irb):18:in `dump' > from (irb):18 > from /home/whitequark/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in > `
' Is not code what I'm trying to serialize just the state of a class, of the class object itself, so when the program start it require all the files needed, included the file which have the class definition, let say: #encoding: utf-8 class Foo @re = 5 def initialize(nickname) @nickname = nickname end def self.change_re(n) @re = n end def self.get_re @re end end Then I want to "refresh" the state of this object, the class object. Let's suppose that when the program was closed, @re was 56, so I want to "start" in some way, with this variable settled to 56, not 5. I'm clear explaining? That is just what I need to do, if you can give me a trick about what's the best way to save this state and restore it I'll be very thankfull. :) -- Posted via http://www.ruby-forum.com/.