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.
Michael B. (Guest)
on 2008-12-21 09: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 B.
Yaser S. (Guest)
on 2008-12-21 09:23
(Received via mailing list)
Don't use puts, use print instead.
print "Welcome. Enter username: "

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