# Converting a Ruby Class Library to a Gem

DevFeed: [Converting a Ruby Class Library to a Gem](<https://devfeed.tech/articles/converting-a-ruby-class-library-to-a-gem-28315.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/ruby/2020/08/12/converting-a-ruby-class-library-to-a-gem.html>)

Author: Fuzzygroup

Published: 2020-08-12T05:48:00Z

Content type: tutorial

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Ruby](<https://devfeed.tech/topics/ruby.md>), [Library](<https://devfeed.tech/topics/library.md>), [Development](<https://devfeed.tech/topics/development.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [blog-post](<https://devfeed.tech/tags/blog-post.md>), [build](<https://devfeed.tech/tags/build.md>), [code](<https://devfeed.tech/tags/code.md>), [dependencies](<https://devfeed.tech/tags/dependencies.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [library](<https://devfeed.tech/tags/library.md>), [ruby](<https://devfeed.tech/tags/ruby.md>)

## AI overview

A practical account of converting Ruby class libraries into gems. It covers creating a repository, configuring gemspec and Gemfile dependencies, building and publishing the gem, and debugging it with irb.

## Source excerpt

Note: Updated on 2022-06-04 to reflect experience with actually maintaining these gems. This blog post talks about my experiences converting a handful of Ruby class libraries to gems. As do a lot of software engineers, I have a series of routines that I bring into almost every Ruby project I tackle that deal with what I consider core stuff you always need: url handling, database stuff, time parsing and so on. Normally I just copy these from project to project but the sheer plethora of them has recently made me see the need to go down the gem route: ❯ mdfind -name url_common.rb | wc -l 62 All of these files are named *common.rb so you will see a number of these on my Github page. I don't claim that any of them are particularly wonderful, brilliant, complete or even well coded; I simply find them useful. In order to figure out which was the right version of the 62 different files I found above, I wrote a separate blog post about using mdfind. The How Here is the quick tldr of how to build a gem. Create a gems directory where you can group all the gems you have. Once you have one, I suspect you're going to have many. Change into that gems directory. Create a repo for the gem and clone it locally. Change into the repo you just cloned. Do a gem signin Do a bundle gem project_name Edit project_name/project_name.gemspec - THIS NEEDS TO HAVE RELEASE LEVEL DEPENDENCIES Update your Gemfile with any dependencies - THIS NEEDS TO HAVE BOTH DEVELOPMENT LEVEL AND RELEASE LEVEL DEPENDENCIES Change into project_name Do a bundle install Do a bundle exec rake build; this gives you the pkg/* stuff below (see next command). Do a gem push pkg/url_common-0.1.0.gem Oh and write the code and the tests. This exists within the lib directory structure. Tips and Tricks 1. Change into the project_name/lib Directory to Run bundle install My first attempt at following the directions gave me this: ❯ bundle install Could not locate Gemfile And the easy solution was to change into the project_name/li