main/players/player.rb
def validate_number(number)
    number_regex = "/\A[-+]?[0-9]*\.?[0-9]+\Z/"
    if number.length != 4
      "Your #{@type} should be 4 digits long".red
    elsif number.any? { |i| i =~ number_regex }
      "Your #{@type} should be compost of digits".red
    elsif number.any? { |i| i.to_i > 5 || i.to_i.negative? }
      "Your #{@type} digits should be between 1 and 6".red
    else
      false
    end
  end
# The number validation according to the rules of the game
# With some console outputs as error messages
The number validation according to the rules of the game
With some console outputs as error messages
The number validation according to the rules of the game With some console outputs as error messages
def validate_number(number)
    number_regex = "/\A[-+]?[0-9]*\.?[0-9]+\Z/"
    if number.length != 4
      "Your #{@type} should be 4 digits long".red
    elsif number.any? { |i| i =~ number_regex }
      "Your #{@type} should be compost of digits".red
    elsif number.any? { |i| i.to_i > 5 || i.to_i.negative? }
      "Your #{@type} digits should be between 1 and 6".red
    else
      false
    end
  end
def validate_number ( number ) number_regex = "/\A[-+]?[0-9]*\.?[0-9]+\Z/" if number . length != 4 "Your #{@type} should be 4 digits long" . red elsif number . any? { | i | i =~ number_regex } "Your #{@type} should be compost of digits" . red elsif number . any? { | i | i . to_i > 5 || i . to_i . negative? } "Your #{@type} digits should be between 1 and 6" . red else false end end
The number validation according to the rules of the game
With some console outputs as error messages
The number validation according to the rules of the game With some console outputs as error messages
number