Mr. Demetrius Michael
Mr. Demetrius Michael

Reputation: 2406

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

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?

Upvotes: 2

Views: 76

Answers (1)

knut
knut

Reputation: 27845

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.

Upvotes: 4

Related Questions