1. Computing

Creating and Distributing Gems with Bundler

By

5 of 6

Add Code

Add any code to the lib directory you need to. You could either be copying code from an existing project, or developing the code right from this directory. If you're developing the code, the rake install command is particularly useful, as you can install the gem and be sure it works before releasing it to the public.

By default, lib/gemname.rb will be the primary file. To require this, you'd run require "gemname" in a Ruby program. You can make any files you want though, but it's a good idea to stick to the "gemname" name to prevent any name clashes. Also note that in your gemspec, the version is read from the file ./lib/gemname/version.rb. Be sure that this file exists, or change your gemspec file to reflect the new location of a version number. Alternatively, you could change your gemspec file every time there's a new release, and hard-code the gem version in this file.

  1. About.com
  2. Computing
  3. Ruby
  4. Advanced Ruby
  5. Add Code

©2014 About.com. All rights reserved.