storable
storable copied to clipboard
Storing Procs do not store local context
Storing of Procs is not complete.
Store Proc to file like this:
class Foo < Storable; field my_proc: Proc; end
def xxx
333
end
File.open("stored.yaml", "w") {|f| f.write Foo.new(Proc.new { xxx + 1 }).to_yaml }
Load that yaml from another Ruby process and execute that block:
class Foo < Storable; field my_proc: Proc; end
Foo.from_yaml(File.read("stored.yaml")).my_proc.call
# (eval):1:in `block in from_string': undefined local variable or method `xxx' for Proc:Class (NameError)
from -e:10:in `call'
from -e:10:in `<main>'
It would be great if local context would be saved, but i'm not sure how that might be possible, because it would mean that there's a need to actually load all the exact environment of the storing process in the process of running that stored proc. But i guess it would be nice to mention that in your readme.
Oh, just so you know - storable
seems to also work nicely in Ruby 2.2.2.