From: Will Conant Date: 2001-10-04T00:27:27+09:00 Subject: [ruby-talk:22013] Re: Marshal won't dump a Proc For the sake of clarity, I thought I'd give an explanation. You can't dump any of those things because they are either handles to system level resources or compiled (parsed) code. In the first case, the reasons are obvious. How do you serialize a socket between you and some other endpoint? That channel of communication could not orthogonally be deserialized and brought back to the state it was in when it was serialized in the first place. In the second case, the reason, I assume, has mostly to do with lexical scoping and closures. A Proc object doesn't just contain a chunk of parsed ruby code, it is also dependent on the scope in which it was created. If you serialized a Proc, you'd have to serialize the entire state of the running application in order to maintain all of the scopes involved. For example: a = "foo" myproc = Proc.new { puts a } Serializing (marshaling) myproc would mean saving the state of it's enclosing scope as well. It's not that such a thing is impossible (there is a Java VM implementation that lets you save the state of a program and resume it right where you left off) it's just not all that practical. If you really want to store some Ruby code and pass it around, save it as text and use eval. -Will Conant -----Original Message----- From: Michael Neumann [mailto:neumann@s-direktnet.de] Sent: Wednesday, October 03, 2001 9:03 AM To: ruby-talk@ruby-lang.org Subject: [ruby-talk:22011] Re: Marshal won't dump a Proc HarryO wrote: > I would really like to be able to dump a block of code via Marshal#dump, > but I get an error saying "can't dump Proc". > > I have a terrible feeling this means it's not possible to do so, but > thought I'd ask, just in case it's actually possible and I'm just doing > something wrong. > > What, exactly, determines whether something can be dumped/loaded via the > Marshal module? Ie, what are its limitations? You cannot dump Proc, Thread, IO (File, Socket ...), Continuation, Method Regards, Michael -- Michael Neumann merlin.zwo InfoDesign GmbH http://www.merlin-zwo.de