Creating a Ruby gem is a lot easier than it seems. Many tutorials about writing gems recommend using something like Jeweler or Hoe to create the structure of the gem for you.
Using such tools will make it much easier to get started with a gem, but building a gem from scratch will help you figure out how exactly those tools organize your gem's structure. Here, we will walk through creating a gem from scratch, without generating any code.
The gem we are creating here is called sudoku, and it is supposed to be able to solve... er... sudoku puzzles. But this tutorial isn't about creating a sudoku solver, so we'll not worry too much about the logic that goes into a sudoku solver and instead focus on how we will package our gem.
The gem name sudoku is obviously taken (by me) and you can't publish the gem to rubygems.org with the same name. (We will look at how to host the gems at rubygems.org in a future post.) I will be using the name sudoku for our gem in the rest of the tutorial, but you can use some other gem name (sudoku-yourname, perhaps?) and replace "sudoku" by your gem's name wherever applicable.
The actual tutorial is split into several posts, each covering one small step in writing the gem. Here are the links:
1. Gem specifications
2. Adding some code
3. Publishing to rubygems.org
4. Setting up Test::Unit
5. Setting up Rspec
I'll hopefully add more posts to this series in the coming days. These are some of the ideas for topics I'll write about:
6. Adding an executable
7. C extensions in Gems
8. More on organizing the code
9. Gem version numbers
I've pushed the code for this project to github, so you can take a look at the latest code there.
[Subscribe to this blog to see when new posts are added to this series, or keep an eye on this page. You can also browse the Ruby related posts on this blog or browse my Delicious bookmarks related to rubygems.]