user2817130
user2817130

Reputation: 55

`initialize': wrong number of arguments (3 for 0) (ArgumentError)

Can someone please explain to a newb why I am getting the wrong number of arguments error? How do I pass the arguments of the new_game object correctly?

load 'admin_logic.rb'
load 'computer_logic.rb'
load 'user_logic.rb'

class TicTacToe

admin_object = Admin.new
computer_object = ComputerLogic.new
user_object = UserLogic.new
new_game = TicTacToe.new(admin_object, computer_object, user_object)

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

end

Upvotes: 0

Views: 2740

Answers (1)

Justin Wood
Justin Wood

Reputation: 10061

TicTacToe.new(admin_object, computer_object, user_object)

That is where your problem is.

Your TicTacToe class does not currently have a constructor. To add one, do something like

def initialize(var1, var2, var3)
    # do something with your variables.
end

You also cannot just write code inside of an object (class) like you are currently doing. An objects purpose is to be a collection of data that belongs to each other. It is meant to be a collection of variables and methods that interact with one another, not to act as a script.

Upvotes: 1

Related Questions