Nexus Designs Nexus Designs - 2 months ago 11
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

Hallo:
_


Is there a way to fix this?

Answer

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"