Ruby: What's the difference between STDIN.gets() and gets.chomp()?

前端 未结 3 1835
不知归路
不知归路 2020-12-15 12:00

What\'s the difference between STDIN.gets() and gets.chomp() in Ruby? Aren\'t they both retrieving raw input from the user?

side question:

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-15 12:31

    because if there is stuff in ARGV, the default gets method tries to treat the first one as a file and read from that. To read from the user's input (i.e., stdin) in such a situation, you have to use it STDIN.gets explicitly.

提交回复
热议问题