From: chiaro scuro Date: 2006-05-02T08:15:57+09:00 Subject: Re: from block to code (also: how to get the bindings of a block) ------=_Part_22451_26674955.1146525354507 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline If it works, it's brilliant! On 5/2/06, Logan Capaldo wrote: > > > 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 =3D ParseTree.new > sexprs =3D pt.parse_tree(A) > end > > > -- Chiaroscuro --- Liquid Development: http://liquiddevelopment.blogspot.com/ ------=_Part_22451_26674955.1146525354507--