I made my very first Ruby gem today! Check it out here!
You can make a Ruby gem! Make an account with Rubygems.org and then follow the following steps. These steps assume you already have some code that works and you want to package it as a gem. It’s always good to keep copies of your code on Github or Bitbucket
- First check if your gem name has been taken by doing a search on Rubygems.org.
- Next, run this in your Terminal:
$ bundle gem <gem-name>
This will create the files you need in your gem package.
- Open up the
gem-name.gemspecfile and replace all the items that start with ‘TODO’ with your own information. Also replace the push host link to rubygems.org. Mine was located on line 19:
spec.metadata['allowed_push_host'] = "https://rubygems.org"
- Go into your lib/gem-name/version.rb file and add your version number in this format: MAJOR.MINOR.PATCH
MAJOR: for big changes to your gem
MINOR: for small additions to your gem
PATCH: bug fixes and such
- Create a new file inside your
gem-name.rband add your classes and methods here.
- Inside a different file located at
lib/gem-name.rbyou can make any module specifications. In this file, the first line should be
require 'gem-name/gem-name'to pull in the file located at
- Add, commit, and push to Git
$ rake install
This will build and install locally
* $ rake build
will build the gem locally
build and push to Rugygems.org
$ gem bump --to minor $ gem bump --to major $ gem bump --to 1.1.1
To add another owner to the gem, type this in your Terminal
$ gem owner gem-name --add <firstname.lastname@example.org>