누군가 newb를 도울 수 있습니까? 나는 그 오류를 얻고있다.메서드 없음 오류, 다른 클래스의 메서드 호출, 인수 전달
: undefined method `computer_name' for nil:NilClass (NoMethodError)
나는 루비에서 메서드를 .method_name이라고 부름니까?
내 initialize 메서드가 올바르지 않아서입니까? 인수를 올바르게 전달하지 않습니까? 나는에서 호출 AM
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
MY CLASS - ADMIN.RB
class Admin
def computer_name
@computer_name = "Watson"
end
end
나는 'require'admin'' 라인을 보지 못했습니다. – vgoff
아니면 전화 캡에 있기 때문에'ADMIN '을 요구합니다. – vgoff
하지만 그 작업이 끝나면 그 클래스가 존재하는 클래스의 인스턴스에서 해당 메서드를 호출해야합니다. – vgoff