Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load File From Local Gem in IRB

Tags:

ruby

rubygems

I have a cloned a ruby gem to my client.

According to the docs here (https://github.com/Jbur43/usps_counties)

I have to require 'usps_counties' in order to load it.

So my path is /usps_counties. From there I load irb and try requiring the usps_counties file, but it can't find it.

I then go to /usps_counties/lib (the file lives in the lib directory), load irb and try requiring it but cant find it.

What am I doing wrong here?

like image 597
adamscott Avatar asked Apr 20 '17 12:04

adamscott


People also ask

How do I load gems?

To install a gem, use gem install [gem] . Browsing installed gems is done with gem list . For more information about the gem command, see below or head to RubyGems' docs. There are other sources of libraries though.

Where to put gem file?

A Gemfile describes the gem dependencies required to execute associated Ruby code. Place the Gemfile in the root of the directory containing the associated code. For instance, in a Rails application, place the Gemfile in the same directory as the Rakefile .

What's Gemfile?

A Gemfile is a file that is created to describe the gem dependencies required to run a Ruby program. A Gemfile should always be placed in the root of the project directory.


1 Answers

If you want to require a local file or gem in irb, I like this method:

irb -I lib -r usps_countries

This allows you to then require the module in your new irb instance:

require 'usps_countries'

Options used:

-I path           Specify $LOAD_PATH directory
-r load-module    Same as `ruby -r'
like image 121
stereoscott Avatar answered Sep 28 '22 06:09

stereoscott