tags:

views:

58

answers:

1

I'd like to slap everything in vendor/gems/gems/**/lib onto the load path. I've got a way to do it, but it just feels clunky. Right now, I'm doing it via:

base = File.expand_path(File.join(File.dirname(__FILE__), "..", "vendor", "gems", "gems"))
libs = File.join(base, "**", "lib")
Dir.glob(libs) { |lib| $LOAD_PATH.unshift lib}

I'm sure there's a better way to do this.

+1  A: 

i think setting up the base path via File is fine. but you don't need to iterate over the list of directories to put them into the $LOAD_PATH. you could use unshift and expand the array.

libs = File.expand_path("../../vendor/gems/**/lib", __FILE__)
$LOAD_PATH.unshift *Dir.glob(libs)
rubiii
A bit shorter to just splat the Dir.glob call, yup. Didn't think of that. But ultimately I'm wondering if there's a way to do this without the Dir.glob call at all?
bergyman
i don't think there is a much better way. you just have to get every single path and put it into the $LOAD_PATH. that's the problem and using Dir.glob seems to be a good solution.
rubiii