我如何要求特定版本的红宝石宝石?

Ken*_*enB 43 ruby gem version oci8

具体来说,红宝石oci8宝石.我安装了1.0.7和2.0.4.我想要1.0.7.

我可以只需要oci8,但我没有得到我想要的版本.

irb(main):001:0> require 'oci8'
=> true
irb(main):002:0> OCI8::VERSION
=> "2.0.4"
Run Code Online (Sandbox Code Playgroud)

我可以要求使用文件的完整路径,它可以工作,但不会是可移植的:

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"
Run Code Online (Sandbox Code Playgroud)

我可以使用gem命令来询问我想要的版本,但它似乎没有实际加载库:

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
Run Code Online (Sandbox Code Playgroud)

如果加载库,我肯定会支持这种最后的方法,而不仅仅是确认它存在于我的系统中.我错过了什么?

Ken*_*enB 72

我的问题是双重的:

1)将gem命令语法与rails environment.rb配置文件中的config.gem行中使用的语法混淆.

2)gem命令后未能发出require命令.

在脚本中正确使用是:

gem 'ruby-oci8', '=1.0.7'
require 'oci8'           # example is confusing; file required (oci8.rb) is not 
                         # same name as gem, as is frequently the case
Run Code Online (Sandbox Code Playgroud)

在rails 2.3.x environment.rb文件中正确使用是:

config.gem "ruby-oci8", :version=>'1.0.7'
Run Code Online (Sandbox Code Playgroud)

感谢http://www.ruby-forum.com/topic/109100上的人们