From: "Ara.T.Howard" Date: 2005-09-10T02:46:30+09:00 Subject: Re: quick print type debugging --8323328-1841519134-1126287987=:15399 Content-Type: MULTIPART/MIXED; BOUNDARY="8323328-1841519134-1126287987=:15399" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323328-1841519134-1126287987=:15399 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE On Sat, 10 Sep 2005, Eric Mahurin wrote: > --- Florian Gro=DF wrote: > >> Eric Mahurin wrote: >> >>> What would be nice is if you could somehow convert the >> block >>> back to text (and put it in the debug message). Anybody >> know >>> how to do that? I know I could make the block be a string >> of >>> the code instead to solve the problem (d{"..."}), but that >>> would be uglier and less efficient when we have debugging >> off >>> (because we have to eval). >> >> See attachment. It's not very general, though. > > Perfect. This was from a ruby quiz, right? Now here is the > new method (didn't need binding_of_caller.rb): > > require 'proc_source.rb' > > $DEBUG_LEVEL =3D ENV['DEBUG']||0 > > module Kernel > def d(level=3D1,&block) > if $DEBUG_LEVEL>=3Dlevel > ret =3D yield > filename,lineno =3D block.source_descriptor > $stderr.printf("DEBUG: %s:%d {%s} =3D> %s\n", > filename,lineno,block.source,ret) > ret > else > yield > end > end > end > > > $DEBUG_LEVEL =3D 1 > x =3D d{1+2} + 3*4 - d{5/6} > > DEBUG: (irb):24 {} =3D> 3 > DEBUG: (irb):24 {} =3D> 0 > =3D> 15 > > Didn't work. Any idea why, Florian? I tried aProc.source > after using lambda to create it and it worked (also in irb). > But, with a block it doesn't seem to. maybe block.call instead of yield? > > >> I think I'd go with the string solution, use >> Binding.of_caller to put it >> into the right context and alias it to a method that does >> nothing when >> $DEBUG isn't set. > > I need to evaluate the block even without debugging because the > result will be used as part of an expression independent of > debugging mode (see above). > > > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > > -a --=20 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | Your life dwells amoung the causes of death | Like a lamp standing in a strong breeze. --Nagarjuna =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D --8323328-1841519134-1126287987=:15399-- --8323328-1841519134-1126287987=:15399--