From: Logan Capaldo Date: 2006-09-05T07:10:28+09:00 Subject: Re: How to store/load persistent data? On Sep 4, 2006, at 1:30 PM, Josef Wolf wrote: > Hello! > > In my previous life (in perl-world) I was used to store persistent > data > with Data::Dumper and load it back with "require '/path/to/file'". > > Now I'm learing ruby and started my first toy-project. I must > admit that > I am not very familiar with OO techniques. > > AFAICS, the ruby way to store persistent data is YAML. Saving an > object > with YAML.dump() works like a charm. But I have trouble to read them > back with YAML.load(). For some reason, the initialize() method of > the > loaded object doesn't get called. I don't understand how an object > can > properly spring in existance without the initialize method? Well the general purpose of initialize is to set up some state / instance variables. That's exactly what the serialized form of the object keeps track of anyway. > For example, > I allocate a TkCanvas in the initialize() method. Such an object > can not > be loaded back properly, IMHO. > Some things aren't serializable in a sane way, that's just a fact of life. > I have one more problem with such an object: There's no > destructor. Should > such an object get out of scope, how do I make sure the allocated > canvas > is destroyed properly? > The garbage collector makes sure that the memory used by objects that go out of scope is reclaimed. > I'm sorry if this is a stupid question, but I am new to both, ruby > and OO. > Please can somebody give an explanation how such an object is > handled in > the ruby-world? >