Forum: Ruby Non-newline gets

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
2d66c63b4d8193d0279bd18200e109d3?d=identicon&s=25 Michael Boutros (michaelboutros)
on 2008-12-21 08:06

I'm writing a CLI and I want to get some additional information after I
first run the script, namely the username. Take a look.

-- code
puts "Welcome. Enter username: "
username = gets.strip
-- /code

That works fine, but the issue is that it takes the username on a new
line, like so:

$ ruby script.rb
Welcome. Enter username:

How can I make it so that the username can be entered on the same line?

Michael Boutros
B09f4659460545e38ece34ddd0d96b46?d=identicon&s=25 Yaser Sulaiman (Guest)
on 2008-12-21 08:23
(Received via mailing list)
Don't use puts, use print instead.
print "Welcome. Enter username: "

Yaser Sulaiman
This topic is locked and can not be replied to.