This works quite nicely - just wondered if there are any improvements to shorten it ?
if (ARGV[0].nil?) then
input=$<
else
input=File.new(ARGV[0],"r");
end
...
# Do something with the input here, for example:
input.each_line do |line|
puts line
end
Only
ARGV ?
works for me,"r"
normally default so can skip it, andFile.new()
may be same toFile()
, SoYou can eliminate the first five lines entirely.
From Pickaxe
Therefore:
Kernel.gets is shorthand for $<.gets, so:
then
and;
are optionalalso you can use the ternary operator: