Persistence of Ruby sessions/programs

R

Renzo Orsini

Hi,

I know there are several ways of saving ruby objects on files, but
there is a simple way of saving ALL the
state of a Ruby program execution (or an irb work session) and then
reload it in another execution (or session)?

In this way I could use Ruby as a sort of Persistent Programming
Language (or Object Database Language).

Thanks!

Renzo Orsini ([email protected]) a newbie to Ruby...
 
G

gabriele renzi

Renzo Orsini ha scritto:
Hi,

I know there are several ways of saving ruby objects on files, but
there is a simple way of saving ALL the
state of a Ruby program execution (or an irb work session) and then
reload it in another execution (or session)?

In this way I could use Ruby as a sort of Persistent Programming
Language (or Object Database Language).


well, using irb you have an hackish solution: you could do an eval of
the history.
Look here[1] for some info on how you could get a persistent history
beetween irb sessions. The next part is just re-evaluating it on startup.
Saving the state of the program would be hard since you can't serialize
closures, singletons and continuations,
Oh, and welcome to ruby :)


[1] http://www.rubygarden.org/ruby?Irb/TipsAndTricks
 
R

Renzo Orsini

Renzo Orsini ha scritto:
Hi,
I know there are several ways of saving ruby objects on files,
but there is a simple way of saving ALL the
state of a Ruby program execution (or an irb work session) and
then reload it in another execution (or session)?
In this way I could use Ruby as a sort of Persistent Programming
Language (or Object Database Language).


well, using irb you have an hackish solution: you could do an eval
of the history.
Look here[1] for some info on how you could get a persistent
history beetween irb sessions. The next part is just re-evaluating
it on startup.

This could be of some help, in effect, but only for simple cases.
Saving the state of the program would be hard since you can't
serialize closures, singletons and continuations,

I would be happy just to save classes, objects and global variables
that I have defined, or a subset of them, but it seems to me that
with Marshal.dump I cannot even save a class

in irb:
irb(main):009:0> class C
irb(main):010:1> def m
irb(main):011:2> 3
irb(main):012:2> end
irb(main):013:1> end
=> nil
irb(main):014:0> Marshal.dump(C, File.new('f','w+'))
=> #<File:f>

then I quit, reload irb and

irb(main):001:0> Marshal.load(File.new('f'))
ArgumentError: undefined class/module C
from (irb):1:in `load'
from (irb):1

(I don't undestand the meaning of this message..., and also I read
that a class is nothing more than an object... :)
Oh, and welcome to ruby :)

Thanks!

Renzo Orsini
 

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

Forum statistics

Threads
474,173
Messages
2,570,937
Members
47,481
Latest member
ElviraDoug

Latest Threads

Top