我如何需要特定版本的 ruby gem?
具体来说,是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的问题有两个:
1)将 gem 命令语法与 Railsenvironment.rb 配置文件中的 config.gem 行中使用的语法混淆。
2) 未能在 gem 命令后发出 require 命令。
脚本中的正确用法是:
rails 2.3.x 环境中的正确用法。rb 文件是:
感谢 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:
Proper usage in a rails 2.3.x environment.rb file is:
Thanks to the folks at http://www.ruby-forum.com/topic/109100
尝试以下语法(而不是 require):
Try the following syntax (instead of require):