ruby - Creating while loop for boolean status of a class method -


GuessingGame with a method called a code named "code>" is .

I am creating some test codes and want to make a loop until the solution is correct:

  class GuessingGame def Initialize (answer) = Answer @ Hull = false end DEF estimate (guess_num) if estimate_num < @answer@hall = false: low eelsf estimate_num & gt; @true = Hull = False: High Elsef estimation_nank = @answer @ hull == right: right end end def solve? Test code that does not work:  
 False says, "There is a number between 1-75" estimate_nank = gets.chomp.to_i end of game.guess (guess_num)  

Ruby does not like my While game.solved? Incorrect and saying that I have the wrong number of arguments.

What am I doing wrong here?

I'm running Ruby 2.1.1p76.

At the top of your class, you need it:

  class Gearganggame attr_reader: solution  

attr_reader <

from the API doctor:

You Attr_reader

Creates an instance variable and the same method which returns the value of each instance variable.

From here you can:

  class guessinggame attr_reader: solve def initialize (answer) @answer = answer @ solved = false end def estimate (Guess_num) if estimate_num & lt; @answer@hall = false: low eelsf estimate_num & gt; @ Entry = False: High Elsef estimation_num = @answer @ hal = true: right end ending  

To begin the game, you just need to make a few changes to your code:

<1>" until game. GuessingGame.new (rand (75)) / Pre>

The loop can be read as long as game.solved = true to keep looping.

I think what you mean to say, while game.solved? Incorrect was while game.solved == incorrect . While game.solved == Incorrect will work fine in your scenario.

In my example, it is like saying to game.solved until game.solved == not true , to execute the same thing Just two different ways to hope that helps!


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -