Script to run against stdin if no arg; otherwise input file =ARGV[0]

后端 未结 3 2124
广开言路
广开言路 2020-12-31 21:14

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],         


        
3条回答
  •  萌比男神i
    2020-12-31 21:47

    then and ; are optional

    also you can use the ternary operator:

    input = ARGV[0].nil? ? $< : File.new(ARGV[0],"r")
    

提交回复
热议问题