Can I use .include?() in a case statement? Ruby
If you want to use a case
instead of an if-elsif
block, then you can write it like this (note the blank space after the case
):
while listen = $stdin.gets.chomp
case
when listen.include?('navigate')
puts "Navigate to #{listen}"
when listen.include?('test')
puts 'test'
when $player_items.include?(listen)
puts "Using the #{$player_items[listen]}"
break
else
puts "Not an option"
end
print "> "
end