

How do rubygems work anyway? - starrhorne
https://www.honeybadger.io/blog/2014/02/04/how-ruby-gems-work

======
jamesbritt
This doesn't explain how rubygems works at all.

For example, when you do

    
    
        require "some_gem"
    

how does _require_ know where to find _some_gem. <ext>_?

First ruby looks in the current load path (i.e. _$:_ ). If it cannot find the
file it then looks in your set of installed gems. If it finds a match it loads
the file and adds that gem path to $:.

[http://ruby-doc.org/core-2.1.0/Kernel.html#method-i-require](http://ruby-
doc.org/core-2.1.0/Kernel.html#method-i-require)

(though those docs say nothing about checking the gem paths.)

 _This makes sense since if your project depends on a certain gem, who knows
where you might reference it. Better load it as early as possible so its code
can be used anywhere._

That's silly. If you are referencing gem code in a file then have that file
require the needed gem. _require_ will only load the file once so you can wait
until you need a gem before you load it.

( _load_ , OTOH, will reload a file as often as you call it).

