Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Nitpicking your nitpick

That's not a nitpick, that's paraphrasing ;)

> It used to not be part of the standard library, but it has been since Ruby 1.9, released in 2007.

That's the mention of 1.8 I made, but it's a bit more complex: it still can be excluded, in two ways:

- at build time via `configure` (and then it's not even there)

- at run time via `--disable-gems`

The interaction between rubygems and ruby core is surprisingly small.

> Rubygems is a default gem

It is not! See `lib/ruby/gems/3.3.0/specifications/default` in any Ruby install, or in source the absence of _any_ gemspec for `rubygems` while there is for bundler[0].

Instead it's, as you mentioned, a default library.

The very principle of gems is that you can have multiple versions of a gem separately installed (to the point of allowing only one to be visible at any one time, activated by `rubygems`-provided `Kernel.gem`). The implementation of that is done by `rubygems` itself so if it were a gem, one would not be able to activate `rubygems` without `rubygems` itself...

This is also why it can be special-case upgraded only via the very special `gem update --system`, which downloads a "gem" named `rubygems-update` (not `rubygems`); scare quotes because it's using the gem format and infrastructure mostly as a delivery mechanism, not by being an _actual_ gem[1] in the traditional sense (well it is a gem, but a gem of an updater, not of `rubygems` itself).

When updated, the new copy of rubygems is installed in `site_ruby`, because the load path is the only mechanism available to define location priority (`ruby --disable-gems -e 'p $LOAD_PATH'`).

Fun fact: the only thing that "prevents" a file present it `${PREFIX}/lib/ruby/3.4.0/rubygems` to not be `load`ed or `require`d is merely that new code in `${PREFIX}/lib/ruby/site_ruby/3.4.0` shall not make reference to it, but it's all perfectly visible otherwise.

    docker run --rm -it ruby:3.4 /bin/bash
    gem update --system
    ls -ld /usr/local/lib/ruby/3.4.0/rubygems /usr/local/lib/ruby/site_ruby/3.4.0/rubygems
    echo 'p __dir__' > /usr/local/lib/ruby/3.4.0/rubygems/foo.rb
    ruby -e 'p $LOAD_PATH; require "rubygems/foo"'
[0]: https://github.com/ruby/ruby/blob/v3_4_7/lib/bundler/bundler...

[1]: https://github.com/ruby/rubygems/blob/v3.7.2/hide_lib_for_up...



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: