What is the fastest way to add catalogs to $ LOAD_PATH in ruby ​​recursively?

I would like to pat everything in the / gems / gems / ** / lib provider on the download path. I have a way to do this, but it's just awkward. Right now, I am doing this through:

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 am sure there is a better way to do this.

+3
source share
1 answer

I think setting the base path through is Filefine. but you don’t need to iterate over the list of directories to put them in $LOAD_PATH. you can use unshiftand expand the array.

libs = File.expand_path("../../vendor/gems/**/lib", __FILE__)
$LOAD_PATH.unshift *Dir.glob(libs)
+2
source

Source: https://habr.com/ru/post/1740028/


All Articles