[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Serializable Proc

Patrick Li

8/19/2008 6:51:00 PM

Hi,
For my current project I need to be able to write an object to disk and
retrieve it later. However, the object contains references to Procs,
which cannot be serialized.

Are there any gems out there that let me serialize a Proc (with support
for closures)?

If there aren't, I'm prepared to write my own. Does anybody know enough
to point me in the right direction?

Thanks a lot
-Cuppo
--
Posted via http://www.ruby-....

4 Answers

James Gray

8/19/2008 8:25:00 PM

0

On Aug 19, 2008, at 1:51 PM, Patrick Li wrote:

> Are there any gems out there that let me serialize a Proc (with
> support
> for closures)?

You mean where the closure would point to the same variable after
being reloaded? I'm not sure how that's going to work.

> If there aren't, I'm prepared to write my own. Does anybody know
> enough
> to point me in the right direction?

You may find some ideas in this old Ruby Quiz:

http://www.rubyquiz.com/q...

James Edward Gray II

Patrick Li

8/19/2008 9:49:00 PM

0

> You mean where the closure would point to the same variable after
> being reloaded? I'm not sure how that's going to work.

Yes. ie.
a = 3
p = lambda{a}
Marshal.dump(p, File.open("myProc.proc", "w")

so that I can go
p = Marshal.load(File.open("myProc.proc", "r"))
p[] #should print 3

The 'connections' between variables should be saved. As well as the
values of the variables currently in the closure.

--
Posted via http://www.ruby-....

James Coglan

8/19/2008 9:55:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

2008/8/19 Patrick Li <patrickli_2001@hotmail.com>

> > You mean where the closure would point to the same variable after
> > being reloaded? I'm not sure how that's going to work.
>
> Yes. ie.
> a = 3
> p = lambda{a}
> Marshal.dump(p, File.open("myProc.proc", "w")
>
> so that I can go
> p = Marshal.load(File.open("myProc.proc", "r"))
> p[] #should print 3
>
> The 'connections' between variables should be saved. As well as the
> values of the variables currently in the closure.



I was hoping ruby2ruby would help, but I can't get it to run on my Windows
box at present -- will try again on Ubuntu later. If anyone figures out how
to do this I would be thrilled, as I'm trying to do a similar thing in
JavaScript. Said language at least gives you a Function#toString method that
gets you part-way there, but getting the values of variables if the function
was created inside a closure is something I've not cracked yet.

James Coglan
http://blog.j...
http://github.c...

Patrick Li

8/19/2008 10:23:00 PM

0

Good to hear I'm not the only one with interest in this.

I'm also read into a gem called NodeWrap. I'm not sure if it's capable
of what I want, but I haven't been able to get it to install so far.
--
Posted via http://www.ruby-....