Ruby: reading from STDIN, if there is something to read.
Posted 09-25-2021 at 01:11 AM by Michael Uplawski
Updated 10-08-2021 at 11:49 PM by Michael Uplawski (Category)
Updated 10-08-2021 at 11:49 PM by Michael Uplawski (Category)
The logic of ARGV and ARGF still escapes me, I am approaching perfection empirically by trial, error and surrender. Now I believe to do stuff the right way, which is highly unsatisfactory.
Today's sura goes like this:
To avoid a hanging program, when there are no data waiting at STDIN, thou shalt write
tty meaning “teletype-writer”, it stands for terminal/console/pseudo-terminal and the like. Something very historical. Something obviously sacrosanct in IT.
I understand that STDIN.tty? returnes true, when the input must be typed on such a terminal. It returns false, when a file has been piped-in to the asking routine, which is what I want, most of the time.
But as Ruby programs are written in a way that you can read them like a book, when the programmer is not an idiot, a routine using this syntax resembles more “Finnegan's Wake” and I do not easily accept that.
But I am a believer. And I am kinda fond of Quarks. Be it that way.
Today's sura goes like this:
To avoid a hanging program, when there are no data waiting at STDIN, thou shalt write
Code:
if !STDIN.tty? # do as you must end
I understand that STDIN.tty? returnes true, when the input must be typed on such a terminal. It returns false, when a file has been piped-in to the asking routine, which is what I want, most of the time.
But as Ruby programs are written in a way that you can read them like a book, when the programmer is not an idiot, a routine using this syntax resembles more “Finnegan's Wake” and I do not easily accept that.
But I am a believer. And I am kinda fond of Quarks. Be it that way.
Total Comments 0