Making a Ruby Gem

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

  1. First check if your gem name has been taken by doing a search on Rubygems.org.
  2. Next, run this in your Terminal:
    $ bundle gem <gem-name>

    This will create the files you need in your gem package.

  3. Open up the gem-name.gemspec file 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"
  4. 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
    Unnamed QQ Screenshot20160106224046
  5. Create a new file inside your lib/gem-name/ folder named gem-name.rb and add your classes and methods here.
  6. Inside a different file located at lib/gem-name.rb you 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 lib/gem-name/gem-name.rb
  7. Add, commit, and push to Git
  8. $ rake install

    This will build and install locally

    * $ rake build

    will build the gem locally

  9. $rake release

    build and push to Rugygems.org

  10. $ 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 <owner@email.com>

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s