Creating your own RubyGems

To view this screencast, add it to your cart and checkout. You can buy this screencast for any price, including FREE!

Now that GemCutter is becoming the standard host for gems, deploying gems couldn’t be easier!

We no longer need tools like hoe, newgem, bones, jeweler or others. Sure, these tools may still be useful, but we don’t need them to create simple gems!

Let’s say you have a Ruby file that you want to share with people. It lets objects bark.

1 class Object
2   def bark
3     puts "woof!  I am #{ self.to_s }!"
4   end
5 end

Very cool library. Let’s share it!

1 Gem::Specification.new do |s|
2   s.name = 'object-bark'
3   s.version = '0.1.0'
4   s.summary = 'Lets object bark!'
5   s.files = Dir['lib/**/*.rb']
6 end

Once your gem is installed, you can use it like any other:

 1 $ irb
 2 >> require 'rubygems'
 3 => true
 4 >> require 'object-bark'
 5 => true
 6 >> Object.bark
 7 woof!  I am Object!
 8 => nil
 9 >> 5.bark
10 woof!  I am 5!
11 => nil

That’s basically all there is to it! To watch me make a gem and ramble on, giving pointers here and there, watch the screencast.

Enjoy!