Let's create another subfolder example and initialize a new project with Bundler.
$ mkdir example
$ cd example
# Initialize a new project
$ bundle init
# Add our gem
$ bundle add contrived_math
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using bundler 2.1.4
Using contrived_math 0.0.0
# Create a file to test it out
$ touch main.rb
Inside of example/main.rb, add the following:
require 'contrived_math'
def main
puts ContrivedMath.add(1, 2)
puts ContrivedMath.subtract(2, 1)
end
main
Assuming that you are still in the example folder, we can run our code like so:
# From example/
$ ruby main.rb
3
1
It works!
Summary
Today's post demonstrated how to deploy your Ruby Gem to the RubyGems repository and demonstrated the usage of installation with Bundler in another example folder.
The next post in this series will look to automate the process as part of a GitHub Actions workflow.