From: Brian Candler Date: 2008-09-16T20:46:18+09:00 Subject: Re: Getting the text (source) of a code block > It occurs to me that the user should probably store the block as a > heredoc or string, but that could result in code duplication later You can use eval to turn the string into a block: class SrcProc attr_reader :src def initialize(src) @src = src @proc = eval "lambda #{src}" end def call(*args,&blk) @proc.call(*args,&blk) end alias :[] :call end block = SrcProc.new "{ |x| puts x+x }" block["hello,"] puts block.src I believe that going in the opposite direction is much harder (google for 'parsetree') -- Posted via http://www.ruby-forum.com/.