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 8086207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:22:39+00:00 2026-06-05T18:22:39+00:00

I am using to Ruby to write a small command line utility to search

  • 0

I am using to Ruby to write a small command line utility to search Pubmed. Right now, I prompt the user for a query and display the results, and the user has the option of appending to the query or entering an entirely new query. I would like to add the ability to edit the current query; i.e. the prompt should come pre-filled with an editable version of the previous query, like so:

Enter query: <PREVIOUS QUERY HERE>

It’s easy enough to print out the previous query next to the prompt, but how do I make this output editable, as if the user had typed it herself?

@casper:
Thank you for the response Casper. I tried the code that you supplied below, and it does indeed work on its own. Strangely enough, it doesn’t seem to work when I try to use it in a gem. My gem is called db_hippo. I added rb-readline as a dependency in my gemspec, and I put the extension to RbReadline in lib/db_hippo/rb-readline.rb

module DbHippo
  module RbReadline
    <CASPER'S EXTENSION HERE>
  end
end

I wish to use the functionality in another submodule of DbHippo, DbHippo::Source. In DbHippo::Source I added at the top:

require 'rb-readline'
require 'db_hippo/rb-readline'

Then in one of the methods of DbHippo::Source, I have:

RbReadline.prefill_prompt(query)
query = Readline.readline("Query: ", true)

The query variable is definitely not empty, but for some reason in this context the prompt doesn’t get prefilled. I also notice that if I put the extension in the same file (lib/db_hippo/rb-readline) without making it a submodule of DbHippo, I get the error: uninitialized constant DbHippo::Source::Readline (NameError) on the line:

query = Readline.readline("Query: ", true)

This all seems to have something to do with proper naming of modules, require statements, and gems. This is the first gem I’ve tried to build. Any idea what’s going wrong here?

  • 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-05T18:22:41+00:00Added an answer on June 5, 2026 at 6:22 pm

    You can do it with RbReadline:

    require 'rubygems'
    require 'rb-readline'
    
    module RbReadline
      def self.prefill_prompt(str)
        @rl_prefill = str
        @rl_startup_hook = :rl_prefill_hook
      end
    
      def self.rl_prefill_hook
        rl_insert_text @rl_prefill if @rl_prefill
        @rl_startup_hook = nil
      end
    end
    
    RbReadline.prefill_prompt("Previous query")
    str = Readline.readline("Enter query: ", true)
    
    puts "You entered: #{str}"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying write a Ruby script that checks if user credentials are valid using
i am using ruby 1.9.2 and also use its csv library.I want to write
Using the ruby Yard doc tool I can write # @param bar [String] def
I'm trying to write a web frontend for Crontab in Ruby using the excellent
I'm trying to write a script in Ruby to parse a Wikipedia article using
I want to write a desktop application using Ruby. I want it platform-independent and
I'm using Ruby v1.9.1 to write a program with the Ackermann-function for my class
I have a question about doing a query through a few associations using Ruby
I'm using Ruby 1.8 and linux (Ubuntu and SLAX), and i need to write
I'm working on a SAML gateway using Ruby/Rails and I'm attempting to write some

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.