Non-newline gets

Discussion in 'Ruby' started by Michael Boutros, Dec 21, 2008.

  1. 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 Boutros
    --
    Posted via http://www.ruby-forum.com/.
     
    Michael Boutros, Dec 21, 2008
    #1
    1. Advertising

  2. [Note: parts of this message were removed to make it a legal post.]

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

    Regards,
    Yaser Sulaiman

    On Sun, Dec 21, 2008 at 9:58 AM, Michael Boutros <>wrote:

    > 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 Boutros
    > --
    > Posted via http://www.ruby-forum.com/.
    >
    >
     
    Yaser Sulaiman, Dec 21, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Mueller
    Replies:
    5
    Views:
    549
    Steven Saunderson
    Jul 10, 2006
  2. spaceboy
    Replies:
    6
    Views:
    366
    =?iso-8859-1?q?Kirit_S=E6lensminde?=
    Nov 18, 2006
  3. John Joyce

    gets gets

    John Joyce, Mar 26, 2007, in forum: Ruby
    Replies:
    2
    Views:
    380
    John Joyce
    Mar 26, 2007
  4. John Joyce

    Return of gets gets

    John Joyce, Apr 23, 2007, in forum: Ruby
    Replies:
    0
    Views:
    215
    John Joyce
    Apr 23, 2007
  5. libsfan01
    Replies:
    5
    Views:
    273
    Jeff North
    Dec 20, 2006
Loading...

Share This Page