hacks/dumpable_proc |
class DumpableProc < DelegateClass |
Example:
y = 42 dp = DumpableProc.new %{ |x| p x, y } dp.call(1) #=> 1 #=> 42 dump_str = Marshal.dump(dp) puts dump_str #=> u:DumpableProc0:538120024: |x| #=> p x, y dp2 = Marshal.load(dump_str) dp2.call(2) #=> 2 #=> 42 DumpableProc.release(dp.id)
Public Methods |
Return the id of a DumpableProc. When you are done with a DumpableProc, and you will not need to _load it again, pass this value to release(). Releasing an id will free memory associated with the DumpableProc; if the DumpableProc is _load'ed again after it has been released, then it will be re-created with a new binding.
Create a new DumpableProc.
str | a string representing the proc |
---|---|
the_binding | the binding to create the proc in (default is to create the proc in the caller's binding) |
id | an id to be associated with the proc; should be left nil |
Determine if a DumpableProc is bound to its original binding, or whether it has been given a new binding.
Returns: true if the proc has its original binding, false otherwise.
Return the (non-dumpable) Proc object associated with this DumpableProc. This is necessary for functions that expect to receive a real proc object and not a delegate object.
Dump a DumpableProc to a string.
Load a DumpableProc from a string.
Release a binding associated with a DumpableProc. If you do not call this method, then you will leak memory.