From: Eric Mahurin Date: 2005-09-10T00:41:52+09:00 Subject: quick print type debugging 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 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