This post originated from an RSS feed registered with Agile Buzz
by Jared Richardson.
Original Post: Writing a Gem: A Very Basic Guide
Feed Title: Jared's Weblog
Feed URL: http://www.jaredrichardson.net/blog/index.rss
Feed Description: Jared's weblog.
The web site was created after the launch of the book "Ship It!" and discusses issues from Continuous Integration to web hosting providers.
I needed to create a Gem this week and was able to get it written with a little help from a local Ruby Guru, Adam Williams. You're got to love having a local user's group with it's own mailing list... and when you post, you get your own blog post. :)
I ended up with this Rakefile, which looks a lot like Adam's example.
require 'rake'
require 'rubygems'
task :default => ["gem"]
desc "Create a gem"
task :gem => ["lib/Hypersonic.rb"] do
spec = Gem::Specification.new do |s|
s.name = "hypersonic"
s.version = "1.0"
s.summary = "hypersonic is a Ruby adapter for the Hypersonic Java database"
s.files = Dir.glob("lib/**/*").delete_if {|item| item.include?(".svn")}
s.autorequire = 'hypersonic'
s.author = "Jared Richardson"
s.email = "jared@jaredrichardson.net"
s.homepage = "http://jaredrichardson.net"
end
Gem.manage_gems
Gem::Builder.new(spec).build
end
Obviously in this example, all the code is in the lib folder. I'll need to add in more files... a Readme or two perhaps. But this should be enough to get you up and running on your first Gem.
To build your gem, just type "rake". Then "gem install "... add a "sudo" if you're on a *nix box.
When you're trying to use your new Gem from irb, you'll need to first require 'rubygems' and then (for my example) require 'hypersonic'. I always forget that step. :)