A gem usually has a Rakefile , which the rake program uses to automate tests, generate code, and perform other tasks. This gem also includes an executable file in the bin directory, which will be loaded into the user's PATH when the gem is installed.
A gemfile is automatically created when you start a new rails application. type rails new appName and then it will be generated automatically. It will also be populated with some gems.
Rubygems.org's Guides is one of the best resources for writing your own gem.
If you're using Bundler in your app, you might want to look at Ryan Bigg's guide to Developing a RubyGem using Bundler and the Railscast on creating gems with Bundler.
If you're interested in tools to help you write gems:
Some tutorials/guides:
This is how I usually create and release Gems:
$ gem install ore rubygems-tasks rdoc rspec
$ mine awesome_gem
cd awesome_gem/
and edit the README.rdoc
and awesome_gem.gemspec
, write code in lib/awesome_gem/
and adding RSpec tests in specs/
.ChangeLog.rdoc
file, run rake spec
and rake rerdoc
, open up html/index.html
and double-check for any typos.rake release
Sit back and bask in the glory of your first Gem. :)
You need not start writing a gem, just write some code, write some tests, use it however you want, and once you are happy with it, use gem this to generate the relevant Rakefile.
It helps if you stick to the approaches other gems take (have a lib directory, avoid naming files in ways that could clash with other gems, write some tests if you can, have a readme), but it's not necessary.
Once you have something you want to share, put it on github and push it to gemcutter.
Don't over think it, don't use hoe or other overkill tools, have fun, don't to anything I wouldn't do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With