2
def get_input(*options)
puts "Choose one:"
options.each do |option|
puts "#{option}"
end
choice = gets.chomp.to_s
options.each do |option|
if choice.include?(option.to_s)
return choice
end
end
puts "Command not found..."
get_input(options)
end
如果用戶輸入了無效的命令,它將再次提供可用的命令,但使用當前值包括[,]。我將如何避免這種情況。循環檢查用戶輸入是否匹配字符串?
請編輯澄清「包括'[,]'我不電流值。不要理解「當前值」是指什麼,或者你的意思是「包括'[,]'」。 –