Lets build a ruby gem together!

There are a few key steps to building a gem.

Here's what we are going to do

  • Figure out what our gem needs to do.
  • Generate the skeleton
  • Write some tests
  • Implement the code
  • Push to GitHub
  • Push to RubyGems

So what should our gem do?

Talk to Bob !

Bob is a very vague teenager. In conversation, his responses are very limited.

- Bob answers 'Sure.' if you ask him a question.

- He answers 'Woah, chill out!' if you yell at him.

- He says 'Fine. Be that way!' if you address him without actually saying anything.

- He answers 'Whatever.' to anything else.

Naming Conventions

  • Ruby gems should be named with all lower case letters, and no punctuation other than _ and -.
  • Use _ for separating words, and - to indicate an extension to an existing gem.
  • Not every single gem follows these conventions, especially if they are old. For example, activerecord should really be active_record. 
  • Refer to the RubyGems Guides.

Generate the skeleton

  • To do the generating, we will use Bundler.

  • Bundler's main job is to help you deal with versions of the dependencies your application needs.
  • It also comes with an awesome generator to help you make gems

> Bundle gem talk_to_bob

Gemfile

is the main file that Bundler uses to track versions of all the dependencies our gem needs

 

              > cat Gemfile

Rakefile

Rake is Ruby's version of the venerable Make tool for building things.

 

> bundle exec rake -T

LICENSE.txt

 

Rubyists almost exclusively love the MIT license, because it makes making money really, really easy

README.md

 

Bundler gives us a pretty okay README to start with.

 The md stands for Markdown, the One True Document Format.

.gitignore

 

Bundler makes sure to create a decent ignore file for git so that we don't check bad things in.

talk_to_bob.gemspec

 

This file specifies all the metadata for our gem

 

Write some tests

 

Every Rubyist except for DHH believes in test-driven development, so we'll write a test first.

 

 

Implement the code

Push to GitHub

Rubyists assume you use GitHub.

It was originally created by some Rubyists

lots of early users were Rubyists

Push to RubyGems

First thing to do is to make sure that packaging it all up works. Let's try:

 

> bundle exec rake install

Push to RubyGems

It successfully built the package, and our 'binary' works. Since this is a feature-complete version of the gem, we should bump the version to 1.0.

 

> bundle exec rake release

Thats it!

Raul Galindo

rgalindo33@gmail.com

Made with Slides.com