How can same program in ruby accept input from user as well as command line arguments

后端 未结 1 1507
广开言路
广开言路 2021-01-18 08:34

My ruby script gets certain inputs from command line arguments. It check if any of the command line argument is missing, then it prompts for an input from user. But i am not

相关标签:
1条回答
  • 2021-01-18 09:35

    gets will only read from the real $stdin (ie the user) if there are no command line arguments. Otherwise it'll take those arguments as files to concatenate as a virtual $stdin.

    You can use STDIN.gets to make sure you're always using the right function.

    You can also delete the arguments from ARGV as you go (or remove them all in one go), your gets should work correctly.

    0 讨论(0)
提交回复
热议问题