我有一个哈希值,其中键名是猫名,值是猫名。有没有办法做到这一点,当人们键入response
不在cats
哈希键中的 a 时,终端可以重新打印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