Choosing a magic number between 0 and 9
Well, you already identified the main issue with your code, and I concur: the imperative style. Also, note that this code should have two loops and you are doing it all in one, that's why you have to use flags all over the place. Since you asked for a functional solution, no while nor loop,  use recursion:

def guess_number(number_to_guess)
  guess = gets.to_i
  if guess == number_to_guess
    puts("You found the correct number: #{number_to_guess}")
  else
    puts(guess &gt; number_to_guess ? "Too high" : "Too low")
    guess_number(number_to_guess)
  end
end

def game
  puts('Find the magic number between O and 9')
  guess_number(rand(10))
  print('Another try? (Y/N): ')
  if gets.strip.downcase == "y"
    game
  end
end

game


If you want to validate the input, create a method def get(validation_regexp) and use it: get(/^\d+$/) and get(/^[yYnN]$/).