Ruby: String Comparison Issues

gets returns the entire string entered, including the newline, so when they type “M” and press enter the string you get back is "M\n". To get rid of the trailing newline, use String#chomp, i.e replace your first line with answer = gets.chomp.

Leave a Comment