How to require specific version of gem in my project

Hi All,

I have installed two different versions of a gem (1.0.0 and 1.0.4)

My code :

···

===============================

require 'test' , '>= 1.3.6'

===============================

it gives me an error

rake aborted!
uninitialized constant Test

but i already installed this version of gem

Can any one help me ......

--
Posted via http://www.ruby-forum.com/.

require doesn't take 2 args (as it doesn't makes sense to be able to require across 2+ versions of the same gem). From the rdoc:

  % ri require
  ...
  === Implementation from Kernel

···

On Dec 5, 2012, at 01:27 , Mallikarjuna Yaddala <lists@ruby-forum.com> wrote:

Hi All,

I have installed two different versions of a gem (1.0.0 and 1.0.4)

My code :

===============================

require 'test' , '>= 1.3.6'

  ------------------------------------------------------------------------------
    require(string) => true or false
  ...

You want to specify that at the gem level using #gem:

  % ri gem
  ...
  (from gem rubygems-1.8.24)
  === Implementation from Kernel
  ------------------------------------------------------------------------------
    gem(gem_name, *requirements)
  ...

So you want:

  gem "test", ">= 1.3.6" # assuming the gem name is actually "test"
  require "test" # assuming there is a file "test.rb" in the gem

BUT... also note that your version specifier above will NOT match either version you have installed.

Ryan Davis wrote in post #1087894:

···

On Dec 5, 2012, at 01:27 , Mallikarjuna Yaddala <lists@ruby-forum.com> > wrote:

Hi All,

I have installed two different versions of a gem (1.0.0 and 1.0.4)

My code :

===============================

require 'test' , '>= 1.3.6'

require doesn't take 2 args (as it doesn't makes sense to be able to
require across 2+ versions of the same gem). From the rdoc:

  % ri require
  ...
  === Implementation from Kernel
  ------------------------------------------------------------------------------
    require(string) => true or false
  ...

You want to specify that at the gem level using #gem:

  % ri gem
  ...
  (from gem rubygems-1.8.24)
  === Implementation from Kernel
  ------------------------------------------------------------------------------
    gem(gem_name, *requirements)
  ...

So you want:

  gem "test", ">= 1.3.6" # assuming the gem name is actually "test"
  require "test" # assuming there is a file "test.rb" in the gem

BUT... also note that your version specifier above will NOT match either
version you have installed.

where i need to add these lines

gem "test", ">= 1.3.6"
require "test"

in rakefile or Gemfile ?

--
Posted via http://www.ruby-forum.com/\.