1
我有一個case
構造,用於檢查標準用戶輸入。如果給定的答案不是用戶給出的,我想重複(或者什麼都不做)。我有case
構造的五個選項:"s"
,"t"
,"c"
,"a"
和"o"
。如果用戶沒有放棄這五個答案,我想重複(或者什麼也不做)。如果沒有給出正確的答案,請重複案例
choice = gets.chomp.downcase
case choice
when 's'
@klass = "S Klass"
@extra = "S Extra"
puts "S Story"
when 't'
@klass = "T Klass"
@extra = "T Extra"
puts "T Story"
when 'c'
@klass = "C Klass"
@extra = "C Extra"
puts "C Story"
when 'a'
@klass = "A Klass"
@extra = "A Extra"
puts "A Story"
when 'o'
@klass = "O Klass"
@extra = "O Extra"
puts "O Story"
end