3
I’m a beginner in Ruby and I’m trying to create a Hangman game to test my language skills. In a part of the code, I need to get a letter chosen by the user and check if that letter is present in the word to be found.
To perform this check, I am using the string method include?, but this method is returning false even when the letter exists in the word. To demonstrate this, I created an example of code below:
print "Digite uma palavra: "
WORD = gets.downcase # A palavra que estou digitando é "bola"
print "Digite uma letra: "
char = gets.downcase
puts WORD.include? char
In this example, if the user type in the second gets the letter "a", the method returns true, but if the user type the letter "b","o" or "l", the method returns false.
Why does this happen? How can I solve the problem?
For those who want to know, I’m using the version
ruby 2.6.5.– JeanExtreme002