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?
knut
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