From: "Ara.T.Howard" Date: 2005-09-10T01:22:24+09:00 Subject: Re: quick print type debugging On Sat, 10 Sep 2005, Eric Mahurin wrote: > Anybody think something like this would be useful? > > module Kernel > def d(message="",&block) > ret = block.call > $stderr.puts("DEBUG: #{block.inspect} #{message} => > #{ret}") if $DEBUG > ret > end > end yeah - but maybe ENV['DEBUG'] vs $DEBUG so one could just DEBUG=1 ruby a.rb $DEBUG makes many packages VERY noisy when loaded... > > > irb(main):020:0> $DEBUG=true > => true > irb(main):019:0> d{1+2*3} > DEBUG: # => 7 > => 7 > irb(main):020:0> $DEBUG=false > => false > irb(main):021:0> d{1+2*3} > => 7 > > If you have an expression to want to see the result of, you > just surround it with d{...}. The block.inspect gives you the > filename and line number and you get the evaluated value. No > need to have a separate "p" or "puts" statement (and possibly > assignment to a variable) because this returns the value. > > 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). > > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > > -a -- =============================================================================== | 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 ===============================================================================