Feature #15112
openIntroducing the short form of `STDERR.puts expr.inspect`.
Description
I sometimes write STDERR.puts obj.inspect
to print debug message to standard error.
I want to write it as STDERR.p obj
.
It can be realized by introducing p
singleton method in STDERR
object.
Updated by duerst (Martin Dürst) over 6 years ago
#warn
writes to STDERR
. What about warn_p
or something similar?
Updated by jeremyevans0 (Jeremy Evans) over 6 years ago
mrkn (Kenta Murata) wrote:
I sometimes write
STDERR.puts obj.inspect
to print debug message to standard error.
I want to write it asSTDERR.p obj
.
It can be realized by introducingp
singleton method inSTDERR
object.
I've heard it is preferable to use $stderr
(the current standard error stream) instead of STDERR
(the original standard error stream) as warn
and similar methods use $stderr
. As $stderr
can be reassigned, there is no guarantee that $stderr.p
would be valid. I suppose you could have STDERR.p
write to $stderr
, but that may be confusing. It may be more generally useful to add a method to IO
that did the equivalent of puts obj.inspect
.
Updated by shevegen (Robert A. Heiler) over 6 years ago
I agree with both what Kenta Murata and what Jeremy Evans wrote (to explain,
I have no personal preference; I think both .p()
would be useful anyway and
I think this was the spirit of the original suggestion; I love p and pp).
Martin suggested warn_p
so I think this addresses more Kenta Murata, but I
think, personally, the net benefit of warn_p
may be significantly smaller
than the "puts
" versus "p
" situation, where I think the gain is quite
significant here, if you write a lot of code that makes use of p
for
output. (This is a bit similar to the proposal to do "require 'pp'
" by
default, which was a good change IMO).
Anyway, my personal opinion is +1 to the idea behind the proposal - I have
no real preference on it being on STDERR
or $stderr
or both; I think it may
be useful on its own, no matter where the method ultimately resides.
Updated by nobu (Nobuyoshi Nakada) about 6 years ago
Any object which has #write
method can be assigned to $stderr
, so we should not expect $stderr
to have p
, I think.
Updated by mrkn (Kenta Murata) about 6 years ago
- Related to Feature #14609: Let `Kernel#p` without an argument print the receiver added
Updated by usa (Usaku NAKAMURA) about 6 years ago
I propose more generalized method on IO
instead of STDERR.p
.
My proposal is IO#putp
.
Updated by mrkn (Kenta Murata) about 6 years ago
- Subject changed from Introdudce the new singleton method STDERR.p to Introducing the short form of `STDERR.puts expr.inspect`.
I totally agree with Jeremy and Usaku, so I want to change the title of this issue.
Updated by hsbt (Hiroshi SHIBATA) 9 months ago
- Status changed from Open to Assigned