From: Sam Smoot Date: 2007-12-30T00:50:00+09:00 Subject: Re: def if ; end - basically impossible? On Dec 28, 10:57 pm, Giles Bowkett wrote: > > > Generator.module_eval(&block) > > > If you're passing the code as a block, the easiest solution may be > > ParseTree? I haven't toyed with it, but Ryan Davis also just released > > ruby_parser apparently, which seems to be a pure-ruby version of > > ParseTree. > > I think that's correct; it's either a Ruby port or a Ruby equivalent. > But it returns s-exps; what I really need is to catch ifs and send > them to an if method. Right. I guess I meant it would seem like you could use ParseTree (or something similar) to detect if/elsif/else/end constructs, and then re- evaluate their interiors as a new proc (I *think* ParseTree can compile a S-Exp to Ruby, but I haven't tried that side personally). That way, you could evaluate the condition, and then send the correct branch along. I guess my assumption is that you don't necessarily *need* to have a method called :if if you can properly detect/handle `if` keywords in the blocks. But that assumption could be off base. Maybe your whole point is building a DSL with :if methods to use. I dunno. Best of luck. :-)