Nexus Designs Nexus Designs - 13 days ago 5x
Ruby Question

Newline created before input when using gets or gets.chomp

Okay, so when I do code like:

puts "Hallo: "
response = gets.chomp

What I want is the user to see something like this:

Hallo: _

(With the underscore being the text input area) But instead, they see something more like this


Is there a way to fix this?


Like Sergio said you need to use print instead of puts, the difference is that print outputs the raw version without any modifications. Puts on the other hand adds a newline at the end.

Puts 'Hallo: " is the same as Print "Hallo: \n"