【发布时间】:2015-01-28 17:29:08
【问题描述】:
如果用户要求,我希望我的 ruby 代码重新运行我的代码。为此,我在最后提供了一个问题,询问用户是否要继续它。我想要它,以便如果 gets.chomp() = yes 它重新运行程序。
我正在考虑让它成为一个循环,但我也不确定如何使用这种方法。
require './codes/AlName.rb'
require './codes/UserName.rb'
system 'cls'
puts("What do you want me to do?")
command = gets.chomp()
commands = [
"time",
"done",
"chat",
"help",
]
#display time (Time.now)
if command == commands[0]
puts(Time.now)
end
if command == commands[1]
exit
end
if command == commands[3]
puts(commands)
end
#chat
if command == commands[2]
system 'cls'
puts("Hello " + UserName)
end
#pauses system
sleep 10
puts("Do you want to continue?")
Response = get.chomp()
if Response == "yes"
(rerun program here)
end
if Response == "no"
exit
end
谢谢
【问题讨论】: