Forum: Ruby Non-newline gets

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Michael B. (Guest)
on 2008-12-21 09:06
Hello,

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:
michaelboutros

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

Thanks,
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: "

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