Non-newline gets


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.

Don’t use puts, use print instead.
print "Welcome. Enter username: "

Yaser S.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs