I am creating a ruby gem and to speed my testing I wrote a script to build and install my gem, then to open irb for me to manually poke around.

How can I run the following ruby commands before passing the irb session to the console:

require 'my_gem'




gem build my_gem.gemspec
gem install my_gem-0.0.1.gem

this is similar to the following question, except I need to know how to pass the session back to the console:

How can I create a bash script which runs irb, then some ruby code?

  • I think that in the middle of the script, you could change by typing '#!rubypath' while replacing rubypath to the path to the ruby executable file. – John Militer Apr 28 '16 at 20:48

An excerpt of irb's manpage on Debian "Jessie" 8:

-r library     Same as `ruby -r'.  Causes irb to load the library using require.

For your example, just use the following command:

irb -r my_gem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.