jlstr
jlstr

Reputation: 3056

How to make a standard Unix Filter using Ruby?

I found this ruby problem on RubyQuiz, which states besides the problem itself, the following:

"The script should be a standard Unix filter, reading from files specified on the command-line or STDIN and writing to STDOUT. Each line of input will contain one integer (between 1 and 3999) expressed as an Arabic or Roman numeral"

I have no idea how to do a Unix Filter using Ruby.. to read files in this case,

Could somebody please enlighten me on how to accomplish this task in the best way possible.

Thanks as always!

Upvotes: 1

Views: 944

Answers (1)

Sam Grossberg
Sam Grossberg

Reputation: 1316

The best way to read files from STDIN is using ARGF, as explained in this answer: Best practices with STDIN in Ruby?

You can write to STDOUT using puts or printf.

For more detailed info about IO in Ruby, read the Ruby Doc: http://www.ruby-doc.org/core/classes/IO.html

Upvotes: 3

Related Questions