From: Ryan Davis Date: 2009-11-16T09:50:28+09:00 Subject: Re: Traversing the contents of a proc (for a DSL) On Nov 15, 2009, at 12:01 , Siemen Baader wrote: > Thanks! The two introspection libs look really interesting. > > I know that there are plenty of templating tools available. But I'm just > playing around with DSLs and chose HTML because it is such a well-known > domain with familiar problems. The point wasn't (necessarily) to use them, but to study them. You simply don't need to traverse the proc to do what you want to do. Example (one of several variants): > class PseudoLisp > def self.convert &b > self.new.instance_eval(&b) > end > > def method_missing(msg, *args, &b) > if args.empty? then > puts "(#{msg})" > else > puts "(#{msg} #{args.join(' ')})" > end > end > end > > PseudoLisp.convert do > happy > sad 42 > end #=> (happy) #=> (sad 42)