Florian Growrote: > And mine's attached to this mail. > > I wrote this a while ago and it works by extracting a proc's origin file > name and line number from its .inspect string and using the source code > (which usually does not have to be read from disc) -- it works with > procs generated in IRB, eval() calls and regular files. It does not work > from ruby -e and stuff like "foo".instance_eval "lambda {}".source > probably doesn't work either. > > Usage: > > code = lambda { puts "Hello World" } > puts code.source > Marshal.load(Marshal.dump(code)).call > YAML.load(code.to_yaml).call Interesting. I was considering taking this approach until I realized I'd have to implement a partial Ruby parser, which is what I see you did. Still, it is pretty cool, though obviously a bit hackish. I wonder if YARV and Ruby byte-code will make it easier for procs to be serialized? I'm not sure how the binding would work (hmmm, if it is just objects maybe they could be serialized as normal), but the proc itself could just be serialized as is if it is self-contained Ruby byte-code. Does anyone know if this is how YARV will be? Because I'm just guessing here. Ryan