Settings

Theme

How do rubygems work anyway?

honeybadger.io

1 points by starrhorne 12 years ago · 1 comment

Reader

jamesbritt 12 years ago

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

(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).

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection