Setting Ruby apart

Why?

Because otherwise it's impossible to update rubygems and other vendored libs in Gentoo. You'll inevitably get file collision. For those who's not familiar with Gentoo I'll explain. File collision is a situation when two packages want to install something into the same place. E.g. two packages install files with the same name in the same directory. In Gentoo file collisions are critical because it's rather unhappy situation for package manager as he can't know which file is better to keep. And ho to uninstall on package correctly. In any case you don't want to have your file overwritten because that may draw your system broken.

How? Episode 1: ripper

The easiest think you might think of is just to rip everything gems related of of the ruby installation. It's not really much.

rm "bin/gem"
rm "lib/rubygems.rb"
rm "lib/ubygems.rb"
rm -rf "lib/rubygems"
rm -rf "test/rubygems"
rm "gem_prelude.rb"

This doesn't really work. First, ruby 1.9 has some Gem related thing build in the core. I mean ruby.c file. Also I'm not sure why but this way externally installed rubygems can not load gems unless you explicitly activate them via gem call. That's pretty annoying because it breaks all executables installed with gems.

How? Episode 2: prelude

So as previous approach didn't really work I continued digging into rubygems. The problem with previous approach is that you have to manually activate gems, i.e. explicitly call gem 'gemname' before requiring any file from that gem. That's annoying and doesn't really work with almost all code out there.

The first this I did is compared what I've deleted from Ruby in previous episode with what rubygems install. The only major difference was gem_prelude.rb. Rubygems doesn't install that. So it must be a part of Ruby. I've inspected the file and appears it does exactly what was missing before. It instruments $: ($LOAD_PATH) so that you could require any file from latest versions of all installed gems. Woo ala! Now everything works as expected

Epilogue

The result is a set of ebuilds. dev-lang/ruby, dev-ruby/rubygems and virtuals/rubygems. Al this you can get from my Gentoo repo.