From: Logan Capaldo Date: 2006-05-02T08:07:24+09:00 Subject: Re: from block to code (also: how to get the bindings of a block) On Apr 30, 2006, at 4:30 PM, chiaro scuro wrote: > On 4/30/06, Eric Hodel wrote: >> >> On Apr 27, 2006, at 12:35 AM, chiaro scuro wrote: >> >> > Does anyone know how to convert a block to a string >> representation of >> > the code it contains? >> >> lib/r2chacks.rb in ZenHacks has this. > > > I'll check it out thanks. > > > If you need the bindings from a proc you are probably trying to solve >> the wrong problem. > > > I would normally agree with you, but this is not a design problem or a > domain-conceptualization problem. > > It's a language-twisting problem that imposes otherwise unimportant > constraints on what I can and cannot do. > > > -- > Chiaroscuro > --- > Liquid Development: http://liquiddevelopment.blogspot.com/ I dunno know about the binding (maybe you can use method_missing + Binding.of_caller) but one to get the code (well the ast, which is pretty darn close) is do something like: require 'parse_tree' def recipe(name, &blk) class A; end A.class_eval { define_method(:code, &blk) } pt = ParseTree.new sexprs = pt.parse_tree(A) end