我正在制作一个基本的“助手”计划.. 无论如何这里是代码:
def sayHelp()
puts "------------List of help and commands-------------"
puts "Help-- Shows a list of commands."
puts "Start [PROGRAM] (PROGRAM ARGS)-- Starts the specified program."
return true
end
version = "1.0"
ccommand = ""
puts "Welcome to RubyBot " + version + "."
puts "------------------------------------"
sleep(3)
system "clear" or system "cls"
puts "Enter \"help\" for a list of commands."
puts "Please enter a command: "
ccommand = gets
if ccommand == "help"
sayHelp()
else
puts "Not right bro"
end
我继续前进并运行这个并输入帮助,但它只是把Not right bro
告诉了我..我做错了什么?
答案 0 :(得分:0)
ccommand = gets
gets
返回的字符串有一个尾随换行符,删除它就可以了:
ccommand = gets.chomp