RCR 255: Add trace info to Kernel#p
Submitted by batkins (Fri May 21 19:05:42 UTC 2004)
Many Ruby programmers use Kernel#p to examine an object's state for debugging purposes. However, p's output does not indicate the file and line from with p was called.
Since Kernel#p doesn't tell the user where it was executed in the file, it is slightly less useful for debugging. If Kernel#p supplied this information, then users of tools like SciTE could quickly jump to the location of output from Kernel#p.
Have Kernel#p output file and line information similar to exception traces. So "p str" would yield:
is in str"
This could cause problems with older scripts that don't expect this to happen. For this reason, it might make sense to enable tracing only if $debug == true
def p *o
prefix = caller.split(/:/).values_at(0, 1).join(":") + ":"
# do whatever p does here, but prepend
# variable prefix to the output
RCRchive copyright © David Alan Black, 2003-2005.
Powered by .