When do we need to “require rubigems”?

This is related to this question:

https://stackoverflow.com/questions/3179797/how-to-use-rubytorrent-or-other-gems

I thought RubyGems is a package manager similar to apt-get on Ubuntu ...

So, when do we need require 'rubygems' in our code?

+4
source share
1 answer

Use require 'rubygems' when you use the gem that you installed with Rubygems. The reason is because Ruby uses Rubygems to determine the stone path set by Rubygems. (cannot find the stone you want to use)

Alternatively, you can pass the -rubygems flag when calling the script, or set export RUBYOPT=rubygems in your profile ( ~/.bashrc or ~/.bash_profile or ~/.profile ), which basically matches the flag, except that he is implicit.

In 1.9, rubygems are required implicilty, and you do not need to do this.

Here are some documents about this http://docs.rubygems.org/read/chapter/3

Note. Some of them have built-in solutions (zozo and faster_rubygems) to avoid Rubygems overhead http://www.ruby-forum.com/topic/212463

+7
source

Source: https://habr.com/ru/post/1314783/


All Articles