From: Siemen Baader Date: 2009-11-16T21:11:24+09:00 Subject: Re: Traversing the contents of a proc (for a DSL) --0015175cdcfc58649a04787be840 Content-Type: text/plain; charset=ISO-8859-1 On Mon, Nov 16, 2009 at 1:50 AM, Ryan Davis wrote: > > 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. > Yes, I will definitely have a look at them! > 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 > "string created" > sad 42 > end #=> (happy) #=> (sad 42) Thanks a lot for the example! There is one caveat with it - I also need to catch the creation of strings. Of course I can work around this by using a method call to construct text (eg text "text body"). Hm.. maybe I can also hook into something with ObjectSpace or String.new; I have to check that out when I come back to my dev machine... -- Siemen > PS. It looks like I'm always double posting for some reason, my apologies, List.. I'll hope it is fixed now.. --0015175cdcfc58649a04787be840--