我如何需要特定版本的 ruby​​ gem?

发布于 2024-08-29 21:32:41 字数 734 浏览 5 评论 0原文

具体来说,是 ruby​​-oci8 gem。我安装了 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"

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

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: uninitialized constant OCI8
    from (irb):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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回忆那么伤 2024-09-05 21:32:41

我的问题有两个:

1)将 gem 命令语法与 Railsenvironment.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

rails 2.3.x 环境中的正确用法。rb 文件是:

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

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

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

思慕 2024-09-05 21:32:41

尝试以下语法(而不是 require):

require_gem 'RMagick' , '=1.10'
require_gem 'RMagick' , '>=1.10'
require_gem 'rake', '>=0.7.0', '<0.9.0'

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'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文