没有收到Ruby的输入

时间:2016-04-01 21:37:30

标签: ruby input output sentinel

我有一个哨兵控制的循环似乎没有接受任何输入:

response = " "
until response == "x" do
  puts"
  Xargonia
  =========
  (N)ew
  (L)oad
  (O)ptions
  (Q)uit"
  reponse = gets
  puts response

当它尝试输出用户输入的内容时,只需要用于初始化的内容。

1 个答案:

答案 0 :(得分:1)

除了语法错误之外,您还要将gets的值分配给reponse而不是response。此外,您还希望通过链接gets来删除String::chomp中的换行符:

response = " "
until response == "x" do
  puts "                              # add space between gets and double-quote
  Xargonia
  =========
  (N)ew
  (L)oad
  (O)ptions
  (Q)uit"
  response = gets.chomp               # rename reponse to response; chain .chomp
  puts response
end                                   # add missing end