Ruby : How to write a gem? [closed]
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 ?
Solution 1:
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:
- Jeweler - Opinionated tool for creating and managing Rubygem projects. There's also a Gemcutter and Jeweler Railscast.
- Hoe - From the guys at seattlrb.
- gem-this adds a bunch of helpful rake tasks.
Some tutorials/guides:
- Creating Your First Gem
- Using bundler and rvm to build a rubygem - Using bundler and rvm to create a gem
- Gem Packaging: Best Practices
- Ruby Gem Recipe - Intro guide to creating a gem using bundler and jeweler
- How to build a ruby gem and host it on gemcutter - tutorial using echoe and gemcutter
- The Truth About Gemspecs - goes over gemspecs and tips for dealing with them
- Packaging with RubyGems - a quickstart guide for Jeweler
- gem that - James Adam - reviews tools that help build gems (hoe, newgem, echoe, gemhub, jeweler, gem this)
- Using Gemcutter's Api from the Commandline
- New Gem with Bundler – Sample Rakefile - Useful rakefile for deploying and publishing a gem
- Let's Write a Gem
- How To Build A Ruby Gem With Bundler, Test-Driven Development, Travis CI And Coveralls, Oh My!
Solution 2:
This is how I usually create and release Gems:
- Sign-up for https://github.com
- Sign-up for https://rubygems.org
$ gem install ore rubygems-tasks rdoc rspec
$ mine awesome_gem
-
cd awesome_gem/
and edit theREADME.rdoc
andawesome_gem.gemspec
, write code inlib/awesome_gem/
and adding RSpec tests inspecs/
. - when you're ready to release, update the
ChangeLog.rdoc
file, runrake spec
andrake rerdoc
, open uphtml/index.html
and double-check for any typos. rake release
- (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. :)
Solution 3:
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.