简体   繁体   中英

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?

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM