views:

376

answers:

2

Specifically, the ruby-oci8 gem. I have both 1.0.7 and 2.0.4 installed. I want 1.0.7.

I can just require oci8, but I don't get the version I want.

irb(main):001:0> require 'oci8'
=> true
irb(main):002:0> OCI8::VERSION
=> "2.0.4"

I can require using the full path to the file, which works, but is not going to be portable:

irb(main):001:0> require 'C:\Ruby\lib\ruby\gems\1.8\gems\ruby-oci8-1.0.7-x86-mswin32-60\lib\oci8'
=> true
irb(main):002:0> OCI8::VERSION
=> "1.0.7"

I can use the gem command to ask for the version I want, but it doesn't appear to actually load the library:

irb(main):001:0> gem 'ruby-oci8', :lib=>'oci8', :version=>'=1.0.7'
=> true
irb(main):002:0> OCI8::VERSION
NameError: uninitialized constant OCI8
    from (irb):2

I would definitely favor this last approach if would load the library, rather than just confirming that it's present on my system. What am I missing?

A: 

Try the following syntax (instead of require):

require_gem 'RMagick' , '=1.10'
require_gem 'RMagick' , '>=1.10'
require_gem 'rake', '>=0.7.0', '<0.9.0'
Jonathan
require_gem appears to be obsolete syntax, replaced by the gem command I referenced in the third example in my question (I am using rubygems 1.3.5). But your suggestion put me on to the thread at http://www.ruby-forum.com/topic/109100, which indicates that I should first issue the gem command, and then require the gem, like:gem 'ruby-oci8', :lib=>'oci8', :version=>'=1.0.7';require 'oci8'But that's not working for me, either - I still end up with 2.0.4 loaded. I suspect that I am hamstrung by the difference between the name of the gem (ruby-oci8) and the name of the file to load (oci8).
+1  A: 

My problem was twofold:

1) confusing gem command syntax with that used in config.gem lines in a rails environment.rb configuration file.

2) failing to issue a require command after the gem command.

Proper usage is:

irb(main):001:0> gem 'ruby-oci8', '=1.0.7'
=> true
irb(main):002:0> require 'oci8'
=> true
irb(main):003:0> OCI8::VERSION
=> "1.0.7"

Thanks to the folks at http://www.ruby-forum.com/topic/109100