0

我想找到一种方法让我的脚本等到用户点击 ENTER,同时使用if...end

input = 3

if input > 2    
    puts "input is greater than 2"
    gets
    puts "this shouldn't appear before I type ENTER"
end

这不起作用,因为我得到

$input is greater than 2
$this shouldn't appear before I type ENTER

我应该用什么代替gets暂停脚本?

感谢您的时间

4

2 回答 2

3

尝试替换gets$stdin.gets

于 2013-02-08T11:40:42.787 回答
0

它对我有用,您确定要从控制台读取吗?

input = 3

if input > 2    
    puts "input is greater than 2"
    puts "please enter your name"
    name = gets
    puts "hi #{name} this shouldn't appear before I type ENTER"
end

o/p

~/Desktop$ ruby demo.rb
input is greater than 2
please enter your name
salil
hi salil
 this shouldn't appear before I type ENTER
于 2013-02-08T11:39:41.043 回答