2. WHAT IS A GEM?
• A RubyGem is a package manager that provides a
standardized format for distributing Ruby programs.
Popular Gems include:
• Gems provide pre-made code to Ruby users, increasing
functionality and efficiency
• They also allow for “lighter” applications because the
Gem code does not need to be a part of the application.
Creating Ruby Gems - Tunnell & Shore
3. LET’S CREATE A GEM
Use “Bundler” to create the standard directory of files
needed for your Gem.
Creating Ruby Gems - Tunnell & Shore
$ bundle gem your_gem_name
This is the Gem directory Bundler
will create locally.
Let’s look at these files more closely.
4. A LOOK AT SOME KEY
FILES
This is where you will tell the world what your
Gem does, how to install it, and how to use it.
Creating Ruby Gems - Tunnell & Shore
README.rdoc
lib/your_gems_name.rb
Gemfile
lib/your_gems_name/version.rb
This is where your application’s
code will live.
Your Gem will need
a version in order to work at all. Try to follow the Ruby
A very minimal file, most of the leg work
happens in the gemspec file [next slide].
6. USING RAKE TO BUILD
AND INSTALL
• Run to see a list of available rake tasks
provided by bundler. You should see:
• Run to add the Gem to your local
system.
• To test for the successful installation, run
and see if it appears.
• Next hop into IRB and , if it
returns true, you are in business.
Creating Ruby Gems - Tunnell & Shore
$ rake -T
rake build # Build your_gem_name-0.0.1.gem into the pkg directory
rake install # Build and install your_gem_name-0.0.1.gem into system gems
rake release # Creates tag v0.0.1 and build and push your_gem_name-0.0.1.g.
$ rake install
$ gem list
require ‘your_gem_name’
7. RELEASE IT TO THE
WORLD
• Create an account at RubyGems.org
• Make sure you have everything working (you should build
some tests) and that your work has been committed
• Run
• Dude, you are officially the author of a RubyGem!
Creating Ruby Gems - Tunnell & Shore
$ rake release
8. WE BUILT A GEM
• Feel free to download it:
A web-scraping gem that provides live news updates related
to the High Yield Bond Markets. Anticipating 10+ million
downloads this week.
Creating Ruby Gems - Tunnell & Shore
$ gem install hybondnews
9. ADDITIONAL RESOURCES
• RubyGems.org Guides (http://guides.rubygems.org/)
• Gem It (http://gemit.us/)
Thank You!
If you have questions, contact us!
Amber - amber.tunnell@flatironschool.com
Ben - benjamin.shore@flatironschool.com
Creating Ruby Gems - Tunnell & Shore