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-g开发者_高级运维et on Ubuntu...
So when do we need to require 'rubygems'
in our code?
Use require 'rubygems'
when you are using a gem that you installed with Rubygems. The reason is that Ruby uses Rubygems to determine the path of the gem that Rubygems installed. (is unable to locate the gem you want to use)
Alternatively, you can pass the -rubygems
flag when you invoke your script, or set export RUBYOPT=rubygems
in your profile (~/.bashrc
or ~/.bash_profile
or ~/.profile
) which is basically the same as the flag, except it is implicit.
On 1.9, rubygems is required implicilty, and you shouldn't have to do that.
Here are some docs about it http://docs.rubygems.org/read/chapter/3
Note: Some have built solutions (zozo and faster_rubygems) to avoid Rubygems overhead http://www.ruby-forum.com/topic/212463
精彩评论