キーの猫の名前と値の猫のインスタンスを持つハッシュがあります。人々がハッシュresponse
のキーにない a を入力したときcats
に、端末がputs "Which cat would you like to know about?"
質問を再印刷するか、「もう一度やり直してください」と入力するようにする方法はありますか? 私は一種の「しばらくの間...他に」を求めていると思います。
puts "Which cat would you like to know about?"
puts cats.keys
response = gets.chomp
while cats.include?(response)
puts "The cat you chose is #{cats[response].age} old"
puts "The cat you chose is named #{cats[response].name}"
puts "The cat you chose is a #{cats[response].breed} cat"
puts "Is there another cat would you like to know about?"
response = gets.chomp
end