get.chomp() 与 STDIN.gets.chomp() 之间有什么区别? [英] What's the difference between gets.chomp() vs. STDIN.gets.chomp()?

查看:31
本文介绍了get.chomp() 与 STDIN.gets.chomp() 之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它们是否相同,或者两个命令之间是否存在细微差别?

Are they the same, or are there subtle differences between the two commands?

推荐答案

gets 将使用 Kernel#gets,它首先尝试读取通过ARGV.如果 ARGV 中没有文件,它将使用标准输入代替(此时它与 STDIN.gets 相同.

gets will use Kernel#gets, which first tries to read the contents of files passed in through ARGV. If there are no files in ARGV, it will use standard input instead (at which point it's the same as STDIN.gets.

注意:正如 echristopherson 指出的那样,Kernel#gets 实际上会回退到 $stdin,而不是 STDIN.但是,除非您将 $stdin 分配给不同的输入流,否则默认情况下它将与 STDIN 相同.

Note: As echristopherson pointed out, Kernel#gets will actually fall back to $stdin, not STDIN. However, unless you assign $stdin to a different input stream, it will be identical to STDIN by default.

http://www.ruby-doc.org/core-1.9.3/Kernel.html#method-i-gets

这篇关于get.chomp() 与 STDIN.gets.chomp() 之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆