public
Last active

Source code for marshaling a Proc in Rubinius. See http://yehudakatz.com/2011/11/19/how-to-marshal-procs-using-rubinius/ for more details

  • Download Gist
marshal_proc.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
module Rubinius
class CompiledMethod
def _dump(depth)
Marshal.dump([@scope, Rubinius::CompiledFile::Marshal.new.marshal(self)])
end
 
def self._load(string)
scope, dump = Marshal.load(string)
cm = Rubinius::CompiledFile::Marshal.new.unmarshal(dump)
cm.scope = scope
cm
end
end
 
class VariableScope
def _dump(depth)
Marshal.dump([@method, @module, @parent, @self, nil, locals])
end
 
def self._load(string)
VariableScope.synthesize *Marshal.load(string)
end
end
 
class StaticScope
def marshal_dump
[@module, @current_module, @parent]
end
 
def marshal_load(array)
@module, @current_module, @parent = array
end
end
 
# work around a bug where GlobalCacheEntries are visible
# in CompiledMethods. This will be fixed in Rubinius.
class GlobalCacheEntry
def rbx_marshal_constant
if @value.is_a?(Module)
@value.name
else
raise ArgumentError, "Unknown type #{self.class}: #{self.inspect}"
end
end
end
 
class BlockEnvironment
def marshal_dump
[@scope, @code]
end
 
def marshal_load(array)
scope, code = *array
under_context scope, code
#under_context *array
end
end
end
 
class Proc
def _dump(depth)
Marshal.dump(@block)
end
 
def self._load(string)
block = Marshal.load(string)
self.__from_block__(block)
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.