I’ve got a library I use for writing temporary debug output to $stderr.
Why $stderr? Because I work with command-line programs that employ a
lot of stdout redirection; I want the debug output to be visible on the
console rather than redirected along with the program’s $stdout.
Q: What’s the prior art? Does some gem already do any of what this
library does?
Q: It this generally useful? That is, does anyone else debug by writing
to the console?
Q: What would be a good name for it, if published as a gem?
Features include:
- Writes to $stderr instead of $stdout
- Can automatically print filename and line number
- Can automatically label the values being output
- Can easily inspect the middle of a call chain
Details:
Kernel#q is like Kernel#p, except that it writes to $stderr.
Kernel#qq is like Kernel#pp from the ‘pp’ library, except that it writes
to $stderr.
Kernel#ql is like Kernel#q, but it also outputs the file/line from which
it was called:
ql "foo" # writes: test.rb:8: "foo"
-
Output can be automatically labeled:
foo = 1
bar = 2
q {‘foo + bar’} # writes: foo + bar = 3
ql {:bar} # writes: foo.rb:9: bar = 2
Kernel#tapq makes it easy to examine the middle of a call chain:
['1', '2'].map(&:to_i).tapq.map(&:even?) # writes: [1, 2]
Best Regards,
Wayne C.