Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8733763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:43:03+00:00 2026-06-13T09:43:03+00:00

I want a simple pre-defined input in ruby. What I mean is that I

  • 0

I want a simple pre-defined input in ruby. What I mean is that I want something to be there by default so the user can edit or just simply press Enter to skip. I’m using STDIN.gets.chomp.

not predifiend : "Please enter a title: "
predefined : "Please enter a title: Inception " // "Inception" is pre-defined input]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:43:04+00:00Added an answer on June 13, 2026 at 9:43 am

    The following is a sub-optimal solution as the default answer is not cleared instantly as the user begins to type:

    prompt = 'Please enter a title: '
    default_answer = 'Inception'
    
    # Print the whole line and go back to line start
    print "#{prompt}#{default_answer}\r"
    # Print only the prompt so that the cursor stands behing the prompt again
    print prompt
    
    # Fetch the raw input
    input = gets
    
    # If user just hits enter only the linebreak is put in
    if input == "\n"
      answer = default_answer
    else # Otherwise the typed string including a linebreak is put in
      answer = input.chomp
    end
    
    puts answer.inspect
    

    If you want such a thing I guess you have to use more advanced terminal features. I guess ncurses could do the job.

    Another option would be to just display the default answer in brackets and simply put the prompt behind that. A lot of simple command line tools do such thing. This could look like this:

     Please enter a title [Inception]:
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want the write a simple application, that input some strings, and do something
Say I want to have a simple web app that takes some user input,
I understand that Silverlight 3.0 has binding but just want a simple example on
I want to build an app engine project that posts to a single pre-defined
I want a simple sign in app in which a user logins successfully if
PSPS: (a Pre-scripted Post-script) It has just come to mind that a more prescient
I just wrote a simple extension that has permission to *.google.com and changes some
Sometimes I want a simple generic Listener without defining my own class. Is there
I'm writing a simple text grabber for C-Style pre-processor. The input text (sample): #if
I want to develop game that generates random simple math equations. easy - 4+5

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.