LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Blogs > Michael Uplawski
User Name
Password

Notices


Rate this Entry

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)

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
Code:
if !STDIN.tty?
  # do as you must
end
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.
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 04:33 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration