January 2024
Intermediate to advanced
718 pages
20h 15m
English
You use require to bring a library into your Ruby program. Some of these libraries are supplied with Ruby, some may have been packaged as RubyGems, and some you may have written yourself. How does Ruby find them?
Let’s start with the basics. When Ruby is built for your particular machine, it predefines a set of standard directories to hold library stuff. Where these are depends on the machine in question. You can determine this from the command line with something like this:
| | $ ruby -e 'puts $LOAD_PATH' |
On our MacOs box, with rbenv installed, this produces the following list:
| | /opt/homebrew/Cellar/rbenv/1.2.0/rbenv.d/exec/gem-rehash |
| | /Users/noel/.rbenv/versions/3.3.0-dev/lib/ruby/site_ruby/3.3.0+0 |
Read now
Unlock full access