我如何需要特定版本的红宝石? [英] How do I require a specific version of a ruby gem?

查看:121
本文介绍了我如何需要特定版本的红宝石?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具体来说,ruby-oci8宝石。我安装了1.0.7和2.0.4。我想要1.0.7。



我只需要oci8,但我没有得到我想要的版本。

  IRB(主):001:0>要求'oci8'
=> true
irb(main):002:0> OCI8 :: VERSION
=> 2.0.4

我可以要求使用文件的完整路径,不会移动:

  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

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

  irb(main):001:0> gem'ruby-oci8',:lib =>'oci8',:version =>'= 1.0.7'
=> true
irb(main):002:0> OCI8 :: VERSION
NameError:未初始化的常量OCI8
from(irb):2

如果加载库,我肯定会赞成最后一种方法,而不是仅仅确认它存在于我的系统中。我缺少什么?

解决方案

我的问题有两个:

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


$ b 2)在gem命令后未能发出require命令。



脚本中正确的用法是:

  gem'ruby -oci8','= 1.0.7'
需要'oci8'#示例令人困惑;需要的文件(oci8.rb)不是
#与宝石名称相同,因为通常情况下



  config.gemruby-oci8,正确使用在rails 2.3.x environment.rb文件中。 :version =>'1.0.7'

感谢 http://www.ruby-forum.com/topic/109100


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?

解决方案

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 in a script is:

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

Proper usage in a rails 2.3.x environment.rb file is:

config.gem "ruby-oci8", :version=>'1.0.7'

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

这篇关于我如何需要特定版本的红宝石?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆