title: How does require rubygems help find rubygem files?
body: <p>While trying to solve <a href="https://stackoverflow.com/questions/6181247/gem-found-in-irb-not-in-ruby">Gem found in irb, not in Ruby</a> , I tried seeing what effect <code>require 'rubygems'</code> had on my own installation:</p>
  
  <pre><code>$ irb
  irb(main):001:0&gt; RUBY_VERSION
  =&gt; "1.8.7"
  irb(main):002:0&gt; $:
  ["/usr/local/lib/site_ruby/1.8", "/usr/local/lib/site_ruby/1.8/x86_64-linux", "/usr/local/lib/site_ruby", "/usr/lib/ruby/vendor_ruby/1.8", "/usr/lib/ruby/vendor_ruby/1.8/x86_64-linux", "/usr/lib/ruby/vendor_ruby", "/usr/lib/ruby/1.8", "/usr/lib/ruby/1.8/x86_64-linux", "."]
  =&gt; nil
  irb(main):003:0&gt; require "rubygems" # Hasn't been required already
  =&gt; true
  irb(main):004:0&gt; require "rubygems" # Will return false, because it's already been required
  =&gt; false
  irb(main):005:0&gt; $: # Same as before
  =&gt; ["/usr/local/lib/site_ruby/1.8", "/usr/local/lib/site_ruby/1.8/x86_64-linux", "/usr/local/lib/site_ruby", "/usr/lib/ruby/vendor_ruby/1.8", "/usr/lib/ruby/vendor_ruby/1.8/x86_64-linux", "/usr/lib/ruby/vendor_ruby", "/usr/lib/ruby/1.8", "/usr/lib/ruby/1.8/x86_64-linux", "."]
  </code></pre>
  
  <p>If requring rubygems doesn't modify <code>$:</code>, then how does it help find files? Does it monkeypatch <code>require</code>? If so, what variable does it use to find rubygem-installed libraries?</p>