我想找到一种方法让我的脚本等到用户点击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
暂停脚本?
感谢您的时间
答案 0 :(得分:3)
尝试将gets
替换为$stdin.gets
答案 1 :(得分: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