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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:38:29+00:00 2026-05-10T16:38:29+00:00

I recently converted a ruby library to a gem, which seemed to break the

  • 0

I recently converted a ruby library to a gem, which seemed to break the command line usability

Worked fine as a library

  $ ruby -r foobar -e 'p FooBar.question' # => 'answer' 

And as a gem, irb knows how to require a gem from command-line switches

  $ irb -rubygems -r foobar   irb(main):001:0> FooBar.question # => 'answer' 

But the same fails for ruby itself:

  $ ruby -rubygems -r foobar -e 'p FooBar.question'   ruby: no such file to load -- foobar (LoadError) 

must I now do this, which seems ugly:

  ruby -rubygems -e 'require 'foobar'; p FooBar.question' # => 'answer' 

Or is there a way to make the 2 switches work?

Note: I know the gem could add a bin/program for every useful method but I don’t like to pollute the command line namespace unnecessarily

  • 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. 2026-05-10T16:38:29+00:00Added an answer on May 10, 2026 at 4:38 pm

    -rubygems is actually the same as -r ubygems.

    It doesn’t mess with your search path, as far as I understand, but I think it doesn’t add anything to your -r search path either. I was able to do something like this:

    ruby -rubygems -r /usr/lib/ruby/gems/myhelpfulclass-0.0.1/lib/MyHelpfulClass -e 'puts MyHelpfulClass' 

    MyHelpfulClass.rb exists in the lib directory specified above.

    That kind of sucks, but it at least demonstrates that you can have multiple -r equire directives.

    As a slightly less ugly workaround, you can add additional items to the ruby library search path (colon delimited in *nix, semicolon delimited in windows).

    export RUBYLIB=/usr/lib/ruby/gems/1.8/gems/myhelpfulclass-0.0.1/lib ruby -rubygems -r MyHelpfulClass -e 'puts MyHelpfulClass' 

    If you don’t want to mess with the environment variable, you can add something to the load path yourself:

    ruby -I /usr/lib/ruby/gems/1.8/gems/myhelpfulclass-0.0.1/lib \    -rubygems -r MyHelpfulClass -e 'puts MyHelpfulClass' 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 180k
  • Answers 180k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I ended up writing my own function to do this.… May 12, 2026 at 3:58 pm
  • Editorial Team
    Editorial Team added an answer Have you tried the Stream.fromIterator method? It produces a stream… May 12, 2026 at 3:58 pm
  • Editorial Team
    Editorial Team added an answer Apart from the fact that your first example is lacking… May 12, 2026 at 3:58 pm

Related Questions

I recently started learning Python and I was rather surprised to find a 1000
I recently converted a site from asp to CF. Unfortunately, alot of the old
Recently I converted a Swing application to Webstart. The process was pretty straightforward, but
I recently converted some Silverlight 3 WCF services to use the new binary http

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.