Here's a simple way to do what you want:
word = "example"
puts "Type a letter: "
guess = gets.chomp
puts word.tr("^#{guess}", "*")
This uses the String#tr
method to replace all but the guess to *
.
The output if you typed e
would be e*****e
.