--- "Ara.T.Howard" <Ara.T.Howard / noaa.gov> wrote: > On Sat, 10 Sep 2005, Eric Mahurin wrote: > > > --- Florian Gro<florgro / gmail.com> 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 = ENV['DEBUG']||0 > > > > module Kernel > > def d(level=1,&block) > > if $DEBUG_LEVEL>=level > > ret = yield > > filename,lineno = block.source_descriptor > > $stderr.printf("DEBUG: %s:%d {%s} => %s\n", > > filename,lineno,block.source,ret) > > ret > > else > > yield > > end > > end > > end > > > > > > $DEBUG_LEVEL = 1 > > x = d{1+2} + 3*4 - d{5/6} > > > > DEBUG: (irb):24 {} => 3 > > DEBUG: (irb):24 {} => 0 > > => 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? Didn't help. lambda works, but a block doesn't: irb(main):052:0> lambda { 1+2 }.source => "1+2" irb(main):053:0> def test(&block) irb(main):054:1> return block.source_descriptor,block.source irb(main):055:1> end => nil irb(main):056:0> test { 1+2 } => [["(irb)", 56], nil] __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com