From: Brian Candler Date: 2008-12-03T17:51:02+09:00 Subject: [ruby-core:20254] Re: Proposal: deferred blocks On Wed, Dec 03, 2008 at 04:06:11AM +0900, Yehuda Katz wrote: > As I clarified earlier, I'm not asking for ParseTree functionality in > Ruby. I'm asking for procs to optionally remember their string form Why not do it the other way round? class MyProc def initialize(source, binding) @source = source @proc = eval("Proc.new { #{source} }", binding) end def to_s @source end def call(*args) @proc.call(*args) end alias :[] :call end x = 4 sub = MyProc.new "|y| x+y", binding p sub.call(1) p sub.call(2) p sub.to_s Works today. Could be made a bit tidier with binding_of_caller, so you don't need to pass in a binding.