有没有一种方法可以在不加载rubygems的情况下调用ruby1.9? [英] Is there a way to call ruby1.9 without loading rubygems?

查看:104
本文介绍了有没有一种方法可以在不加载rubygems的情况下调用ruby1.9?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以ruby 1.9真的很好,因为它会自动需要rubygems,因此当你调用 require'somegem'时,如果没有首先需要rubygems,它就会工作,这通常是很棒的。



但是我有很多使用ruby的shell脚本,而且他们通常不依赖rubygems。 shell工具应该立即运行,并且不加载rubygems是一个主要的拖延,主要是因为它涉及到一堆散布着小文件的磁盘操作。



我希望能够告诉ruby,当运行这些shell脚本时,跳过加载gem。理想的情况是,像shebang这一行中的#!ruby --no-rubygems

有没有这样的事情?或者,也许一个编译选项,会告诉ruby ruby​​gems必须手动要求?

解决方案

是的,您可以使用 disable-gems 选项。



请注意,shebang行中是否传递选项取决于您的操作系统。有些操作系统根本不支持传递选项 ,有些仅支持传递一个选项或参数。

所以,如果你有例如

 #!/ usr / bin / env ruby​​ 

然后,您很可能无法将选项附加到最后。如果OTOH将它改为

 #!/ usr / local / bin / ruby​​ --disable-gems 

然后,您已经将Ruby二进制文件的位置硬连接到您的脚本中。



当然,有些操作系统根本不解释shebang行 。 (毕竟,它们从未在任何标准中被指定,甚至没有被正确记录。)

另一种方法是设置 RUBYOPT 环境变量,并简单地切换到另一个环境,使用 RUBYOPT unset(或设置为 -w code>,我个人最喜欢)用于Ruby开发。


So ruby 1.9 is really nice in that it'll automatically require rubygems, and hence when you call require 'somegem' without first requiring rubygems it'll work, and that's generally awesome.

But I have a ton of shell scripts using ruby, and they generally don't rely on rubygems. Shell tools should run instantly, and loading rubygems for nothing is a major drag, mostly because it involves a bunch of disk operations with scattered small files.

I want to be able to tell ruby, when running these shell scripts, to skip loading gems. Ideally, something like #!ruby --no-rubygems in the shebang line.

Is there such a thing? Or maybe a compile option that'll tell ruby rubygems must be required manually?

解决方案

Yes, you can use the --disable-gems option.

Note that whether or not passing options in the shebang line works depends on your operating system. Some operating systems don't support passing options at all, some only support passing one option or argument.

So, if you have for example

#!/usr/bin/env ruby

Then it's pretty unlikely that you will be able to attach the option to the end. If OTOH you change that to

#!/usr/local/bin/ruby --disable-gems

Then you have hardwired the location of the Ruby binary into your script.

And of course there are operating systems that don't interpret shebang lines at all. (After all, they were never specified in any standard, and aren't even properly documented.)

An alternative would be to set the RUBYOPT environment variable in your shell environment and simply switch to a different environment with RUBYOPT unset (or set to -w, my personal favorite) for your Ruby development.

这篇关于有没有一种方法可以在不加载rubygems的情况下调用ruby1.9?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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