我正在尝试编写一个基于文本的ruby游戏,我无法弄清楚什么是不允许我的代码使用.includes?方法
这些是我得到的错误:
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 move ==“run”方法,它可以正常工作,但是当我确实包括?弹出此错误。我不确定为什么它让我做==但不是.includes?
这是我的主要游戏.rb代码:
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
和我的其他文件levels.rb是这样的:
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
感谢任何帮助。谢谢。
答案 0 :(得分:1)
您的代码中有includes?
。方法是include?
(没有's)