DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Gabriel has posted 2 posts at DZone. View Full User Profile

Require A Specific Version Of A Gem

05.04.2010
| 8005 views |
  • submit to reddit
        If you want to require a specific version of a gem you have to both specify the version using the gem method AND require the gem as you normally do. If you don't do this you will receive an error like "NameError: uninitialized constant RestClient".

Some gems make this more complex by having a gem name that is not the same as the name of the file you then have to require like in the example below.

#!/usr/bin/env ruby -rubygems

gem 'rest-client', '= 1.5.0' #Install with: sudo gem install rest-client -v 1.5.0

require 'rest_client'

puts RestClient.get("http://example.com").body