Ruby : How to write a gem?

RubyRubygems

Ruby Problem Overview


I'd like to write a package for Ruby and make it available as a gem.
What are the tools, steps and pitfalls ?
Are there any good tutorials, screencasts, etc., which helped you learning how to do it ?

Ruby Solutions


Solution 1 - Ruby

Rubygems.org's Guides is one of the best resources for writing your own gem.

If you're using Bundler in your app, you might want to look at Ryan Bigg's guide to Developing a RubyGem using Bundler and the Railscast on creating gems with Bundler.

If you're interested in tools to help you write gems:

Some tutorials/guides:

Solution 2 - Ruby

You need not start writing a gem, just write some code, write some tests, use it however you want, and once you are happy with it, use gem this to generate the relevant Rakefile.

It helps if you stick to the approaches other gems take (have a lib directory, avoid naming files in ways that could clash with other gems, write some tests if you can, have a readme), but it's not necessary.

Once you have something you want to share, put it on github and push it to gemcutter.

Don't over think it, don't use hoe or other overkill tools, have fun, don't to anything I wouldn't do.

Solution 3 - Ruby

This is how I usually create and release Gems:

  1. Sign-up for https://github.com
  2. Sign-up for https://rubygems.org
  3. $ gem install ore rubygems-tasks rdoc rspec
  4. $ mine awesome_gem
  5. cd awesome_gem/ and edit the README.rdoc and awesome_gem.gemspec, write code in lib/awesome_gem/ and adding RSpec tests in specs/.
  6. when you're ready to release, update the ChangeLog.rdoc file, run rake spec and rake rerdoc, open up html/index.html and double-check for any typos.
  7. rake release
  8. (Optional) submit a link and explanation of your new awesome gem to http://rubyflow.com

Sit back and bask in the glory of your first Gem. :)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionglmxndrView Question on Stackoverflow
Solution 1 - RubyJack ChuView Answer on Stackoverflow
Solution 2 - RubycwninjaView Answer on Stackoverflow
Solution 3 - RubypostmodernView Answer on Stackoverflow