From: James Britt Date: 2010-02-01T02:32:15+09:00 Subject: Re: "require 'rubygems'" In Your Library/App/Tests Is Wrong? Josh Cheek wrote: >> > Perhaps I am confused, is there a problem with this code?: > begin > require 'mechanize' > rescue LoadError > require 'rubygems' > require 'mechanize' > end > >>From here, it appears that if you have your own way of managing gems, then > rubygems will not be loaded, because you will not experience a LoadError. > Thus it satisfies that I don't tell you how to load your gems, while for the > vast majority of people, it simply works the way they want / expect it to. > > If this is not acceptable, please be explicit in explaining why (perhaps an > example of how it would require rubygems if you are using a different > manager). Suppose I have an app that uses Mechanize, but I've unpacked the Mechanize gem into a local directory. When my app starts I munge $: so that my own local relative dirs are checked to find files. But suppose I screw that part up. :( My app calls your code, and when your code runs it should be finding my unpacked copy of Mechanize, but because I have some error in my code, it falls back to loading the rubygems version. It also now has rubygems loaded, so other attempts at controlling the load path may quietly do something I did not want. Sadness follows. BTW, I've seen the above style of secret gem-loading code used *inside* a gem. ActiveRecord, I think. This is insane. If I'm using something as a gem then *I already have* rubygems loaded, and if I'm not using your code with rubygems (say I've unpacked a gem) then I likely *do not* want rubygems loaded, and if there is a loading error it needs bubble up, not be quietly caught and "fixed." -- James Britt www.jamesbritt.com - Playing with Better Toys www.ruby-doc.org - Ruby Help & Documentation www.rubystuff.com - The Ruby Store for Ruby Stuff www.neurogami.com - Smart application development