11
I'm not sure I've seen this addressed, but I am wondering what is the best way to do multiple requires in a ruby script. I have come up with a couple rudimentary examples which I will outline below, but I'm not sure if there is a best practice for this -- my search results have come back with nothing.
0) Bunch of includes & exceptions (I'll leave the rescue out)
require 'rubygems'
require 'builder'
1) String array
torequire = ['rubygems', 'builder']
begin
torequire.each do |req|
require req
rescue LoadError => e
# Not sure if this is great either
puts "Missing required gem: " + e.message.split[-1]
exit
end
2) ??
Is there a large problem created from loading them all from a string array? You could specify version requirements or locations similarly, I'm just wondering if there is a problem with doing it this way.