MicroPosts
- Ruby: default gems
Ruby's stdlib is composed of 3 different elements:
- Standard libraries that are embedded in the language's source
- Default gems that can be required, are maintained by the core team, and cannot be removed
- Bundled gems that come installed with Ruby and can be removed
Full list on stdgems.org.
- Ruby gem activation
This is how you use a Ruby gem usually:
require 'foo' Foo.barFor the
requireto work, the gem needs to be available on theLOAD_PATH:ruby -e 'puts $LOAD_PATH'The act of adding a gem to the
LOAD_PATHis called "activating a gem".In a vanilla Ruby situation, you can add a directory to the
LOAD_PATHwith:ruby -I ./foo/lib -e "puts(require 'foo')" # trueMore often, you deal with a bundle that contains a Gemfile:
gem 'foo'To activate the gems from the Gemfile (taking into account the versions from Gemfile.lock):
require 'bundler/setup' require 'foo'or (equivalent):
require 'bundler' Bundler.setup require 'foo'Notice that the
setupstep will first clear theLOAD_PATHand activate only the gems in the bundle.For example, Rails does it here and here.
If you've ever wondered what the hell is up with
bundle exec ..., the answer is simple: Bundler activates the gems in the bundle with something likeRUBYOPT="-rbundler/setup" ruby ...Of course, things are more complex than that. But this should give you a starting point.