From: Ryan Davis Date: 2008-01-04T19:38:42+09:00 Subject: Re: parse tree? On Jan 3, 2008, at 21:06 , Giles Bowkett wrote: > Well, I'm writing a code generator, and I thought I was very close to > finished, except I was basically doing this: > > generated_code = Generators.module_eval(&block) > > And that works great for tiny bits of code, it works at the statement > level, but when I want to just collect up *all* the statements in a > block, the whole thing kinds of goes south. So I have something which > generates all the individual statements perfectly but completely falls > apart when I want to create several statements. Does this help? > >> require 'rubygems' ; require 'ruby2ruby' > => true > >> def code_for █ block.to_ruby; end > => nil > >> code_for do > ?> single_line(statement) > >> statement(:which => spans, > ?> :multiple => lines) > >> end > => "proc {\n single_line(statement)\n statement(:which => > spans, :multiple => lines)\n}" There are clean ways to ensure it isn't a proc as well.