Does requiring a gem load everything, including things I don't use?

一笑奈何 提交于 2020-02-02 11:45:45

问题


Assume x is a gem, that contains both Hello and Goodbye classes.

If I write a program that require 'x', but only uses the Hello class. Is the Goodbye class loaded as well?


回答1:


You include scripts or files, not gems.

With

require 'x' 

you load the file x.rb. Which x.rb you load is defined by the search path, the search pathes can be modified by gem definitions (what you didn't use in your example code).

Everything inside the file x.rb is loaded. If x.rb contains other require commands, those files are also loaded.



来源:https://stackoverflow.com/questions/10001106/does-requiring-a-gem-load-everything-including-things-i-dont-use

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