From: Csaba Henk Date: 2005-03-18T07:34:56+09:00 Subject: encapsulating rubygems so that my users don't need to be aware of it Hi! Say in appfoo I use lib_a, lib_b and lib_c. I know if you want to use appfoo, and you have some of these libs as gems, you can do it by inserting a "require rubygems" to the beginning of appfoo, or running it as "ruby -rubygems ", or by tinkering with $RUBYOPTS. But what if now I say *I* am aware of rubygems, and I want to let my users not to care about whether this or that is installed as a gem or not? One I could come up with is the following: I start apfoo like this: %w(lib_a lib_b lib_c).each {|lib| begin require lib rescue LoadError require rubygems require lib end } -- but it's ugly, and gives a useless error message if both rubygems and one of the libs is missing. I also tought of begin require rubygems rescue LoadError end require lib_a require lib_b require lib_c but it pulls in rubygems unnecessarily if it's installed, but lib_* are not gems. The following monster: %w(lib_a lib_b lib_c).each {|lib| begin require lib rescue LoadError begin require rubygems rescue LoadError end require lib end } should work like a charm, but it's ridiculously baroque. Any better idea? Csaba