Nexus Designs Nexus Designs - 1 year ago 71
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?

Answer Source

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"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download