Over a million developers have joined DZone.

Require A Specific Version Of A Gem

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

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}