mercredi 18 mai 2022

Why is there an argument although I don't give an argument?

I am new to ruby and I am trying to create a hangman game, to do so I need to create a new game each time the user click on a button.

First step is to create the same object each time the methode create will be called (it will be different because of the .sample.

I am trying to create an object with the initialize method in my model.rbfile.

Here is my code :

class Game < ApplicationRecord

  has_many :guesses

  attr_accessor :word_to_guess, :health_bar, :game_status


  def initialize
    @word_to_guess = words.sample
    @health_bar = 5
    @game_status = game_status[0]
  end

  words = [
    "spokesperson", "firefighter", "headquarters", "confession", "difficulty", "attachment", "mechanical",
    "accumulation", "hypothesis", "systematic", "attraction", "distribute", "dependence", "environment",
    "jurisdiction", "demonstrator", "constitution", "constraint", "consumption", "presidency", "incredible",
    "miscarriage", "foundation", "photography", "constituency", "experienced", "background", "obligation",
    "diplomatic", "discrimination", "entertainment", "grandmother", "girlfriend", "conversation", "convulsion",
    "constellation", "leadership", "insistence", "projection", "transparent", "researcher", "reasonable","continental",
    "excavation", "opposition", "interactive", "pedestrian", "announcement", "charismatic", "strikebreaker",
    "resolution", "professional", "commemorate", "disability", "collection", "cooperation", "embarrassment",
    "contradiction", "unpleasant", "retirement", "conscience", "satisfaction", "acquaintance", "expression",
    "difference", "unfortunate", "accountant", "information", "fastidious", "conglomerate", "shareholder",
    "accessible", "advertising", "battlefield", "laboratory", "manufacturer", "acquisition", "operational",
    "expenditure", "fashionable", "allocation", "complication", "censorship", "population", "withdrawal",
    "sensitivity", "exaggerate", "transmission", "philosophy", "memorandum", "superintendent", "responsibility",
    "extraterrestrial", "hypothesize", "ghostwriter", "representative", "rehabilitation", "disappointment",
    "understanding", "supplementary", "preoccupation"
        ]

  game_status = ["Game not started yet", "In Game", "You win", "You loose"]
  

end

When I do a Game.newin my console, it returns this error message :

"ArgumentError: wrong number of arguments (given 1, expected 0) "

I dont understand, what argument am I giving ?

Aucun commentaire:

Enregistrer un commentaire