def cafeteria
puts "The cafeteria is a mess, as you walk into the kitchen all the pots and pans are all over the floor."
puts " The freever is open, everything has spoiled, and it smells awful!"
puts "At the far end of the kitchen a set of knives is lying on the floor."
puts "What do you do?"
prompt()
action = gets.chomp
if action.include? 'knife' or 'knives'
puts "Yes! now you have a weapon."
puts "Now what?"
elsif action == "leave."
return :hallway
else
puts "I don't understand."
return :death
end
end
答案 0 :(得分:1)
action.include? 'knife' or 'knives'
将始终产生真值。 (即使字符串中没有kinfe
,knives
)
action = 'asdf'
# => "asdf"
action.include? 'knife' or 'knives'
# => "knives"
因为它被解释为(action.include? 'knife') or 'knives'
也许你的意思是关注?
action.include? 'knife' or action.include? 'knives'
# => false