The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Writing a Gem: A Very Basic Guide

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jared Richardson

Posts: 1031
Nickname: jaredr
Registered: Jun, 2005

Jared Richardson is an author, speaker, and consultant who enjoys working with Ruby and Rails.
Writing a Gem: A Very Basic Guide Posted: Sep 8, 2006 12:16 PM
Reply to this message Reply

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.
Latest Agile Buzz Posts
Latest Agile Buzz Posts by Jared Richardson
Latest Posts From Jared's Weblog

Advertisement

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. :)

Jared

Read: Writing a Gem: A Very Basic Guide

Topic: Code Optimization Previous Topic   Next Topic Topic: Quick Hits at ESUG

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use