1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Creating and Distributing Gems with Bundler


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. Technology
  3. Ruby
  4. Advanced Ruby
  5. Add Code

©2014 About.com. All rights reserved.