有人可以帮助newb吗?我遇到了错误;没有方法错误,来自不同类的调用方法,传递参数
: undefined method `computer_name' for nil:NilClass (NoMethodError)
我想在ruby中调用带.method_name的方法吗?
是因为我的初始化方法不正确?没有正确传递参数?
load 'admin_logic.rb'
load 'computer_logic.rb'
load 'user_logic.rb'
class TicTacToe
def initialize(admin_object, computer_object, user_object)
admin_object = Admin.new
computer_object = ComputerLogic.new
user_object = UserLogic.new
@new_game = TicTacToe.new(admin_object, computer_object, user_object)
end
end
puts "Hello, I\'m " + @new_game.computer_name + ", let\'s play Tic Tac Toe! What is your name?"
puts "Great " + @new_game.user_name + ", you\'ll be " + @new_game.user_sign + ". Please choose where you want to go."
puts 'The game board is the following, please remember!'
puts ' a1 | a2 | a3'
puts " --- --- ---"
puts ' b1 | b2 | b3'
puts " --- --- ---"
puts ' c1 | c2 | c3'
@new_game.user_sign
@new_game.computer_sign
@new_game.game_board
@new_game.winning_propositions
while @new_game .computer_win != true do
@new_game.user_turn
@new_game.draw_game_outcome
@new_game.player_first_turn_check?
@new_game.draw_game_outcome
end
我的课,我称之为FROM - ADMIN.RB
class Admin
def computer_name
@computer_name = "Watson"
end
end
我不会看到'需要'管理员行。 – vgoff
或者'需要'ADMIN'',因为它在呼叫上限。 – vgoff
但是,在完成之后,您需要在其存在的类的实例上调用该方法。 – vgoff