How to store/load persistent data?

J

Josef Wolf

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? For example,
I allocate a TkCanvas in the initialize() method. Such an object can not
be loaded back properly, IMHO.

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?

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,690
Members
48,796
Latest member
Greg L.

Latest Threads

Top