Best practices with STDIN in Ruby?
Posted
by griflet
on Stack Overflow
See other posts from Stack Overflow
or by griflet
Published on 2008-11-07T19:14:51Z
Indexed on
2010/05/13
21:44 UTC
Read the original article
Hit count: 181
I want to deal with the command line input in Ruby:
> cat input.txt | myprog.rb
> myprog.rb < input.txt
> myprog.rb arg1 arg2 arg3 ...
What is the best way to do it? In particular I want to deal with blank STDIN, and I hope for an elegant solution.
#!/usr/bin/env ruby
STDIN.read.split("\n").each do |a|
puts a
end
ARGV.each do |b|
puts b
end
© Stack Overflow or respective owner