Is there a way to call ruby1.9 without loading rubygems?

淺唱寂寞╮ 提交于 2019-12-22 04:33:16

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/3252917/is-there-a-way-to-call-ruby1-9-without-loading-rubygems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!