I'm trying to write a text-based ruby game, and I can't figure out what's not allowing my code to use the .includes? method.
These are the errors I'm getting:
game.rb:31:in `home': undefined method `includes?' for "run":String (NoMethodError)
from game.rb:20:in `call'
from game.rb:20:in `play'
from game.rb:69:in `<main>'
If I use the if move == "run" method, it works fine, but when I do include? this error pops up. I'm not sure why it lets me do == but not .includes?
This is my main game.rb code:
require './levels'
include Levels
class Game
def initialize(start)
@quips = [
"You died. Noob.",
"Nice job, you lost.",
"Looooooserrrrr."
]
@start = start
end
def play
next_room = @start
while true
puts "\n---------"
room = method(next_room)
next_room = room.call
end
end
def home
home_text
puts " Do you run out to see what's going on or stay inside and hope the problem goes away?"
prompt; move = gets.chomp
if move.includes? "run"
return :town
else
die("Your house catches on fire and collapses on you.")
end
end
end
a_game = Game.new(:home).play
and my other file levels.rb is this:
module Levels
def prompt
puts
print " > "
end
def die(why)
puts
puts " #{why} #{@quips[rand(@quips.length)]}"
Process.exit(1)
end
def bad_input
puts <<-TEXT
Learn to follow instructions!
TEXT
return :die
end
def home_text
puts <<-TEXT
You wake up to the smell of smoke in your room. Jolting up from your bed, you
look around the room and see a heavy cloud of smoke covering your ceiling. There
are piercing sounds of screaming outside, coupled with terrorizing roars and howls.
TEXT
end
end
Any help is appreciated. Thank you.