IMHO the question is whether a string is the proper interface to a
Agreed. I think the problem originates from the the Unix/Linux/Solaris
world, where it is often not possibile to specify stdin/stdout/stderr
in the same way as a filename (some however do, AFIK, by allowing
like “/dev/fd0” to be used as a “filename” denoting stdin).
out << …
The second form is more flexible than the first one because you can
pass not only file names but IO objects, Strings, StringIOs etc. And
the second method does not need the “-” hack because you can just pass
I would rarely use the “-” convention within my program; only as a way
receive this uniformly from the outside. And, yes, I’m not that much
satisfied with using just a dash to denote it. It only happened to be
used that way so often, so people are likely familiar with it.
Also, when using ARGF for reading then you automatically get input
from stdin if there are no arguments in ARGV. This is another
situation where you do not need “-” as representative for stdout or
If it were just for this case, we would for sure not need a “-”. But
consider the Linux cat command, which takes an arbitrary number of
filenames, concatenates their content and writes it to stdout. Here
an example invocation of cat:
middle|cat foo - bar >baz
This first copies the content of file foo to baz, then appends the
of the process “middle” to baz, and finally appends file bar to baz.
the user interface point of view, you need some way here to represent
stdin on the command line, and by convention this is done by cat.
If you implement this in Ruby, you certainly have to deal with “-”
for example along the way Erik V. proposed. I use for instance in
code calls like this:
f = ARGV[n]=="-" ? $stdin : File.open(ARGV[n])
to implement this behaviour.
This for sure can be done explicitly, but if things are done over and
in the same way by different teams of programmers, it makes sense to
a general solution from it. And, as some people in this list pointed
maybe it would be really best to provide such a feature as gem and see
whether it becomes popular. I will see whether I can do it (as I have
implemented a Gem so far).