Question

I have a gem that I have written that has a number of handlers, each of which has their own ruby file in the gem. I need to add the ability to specify a file on the command line that will be loaded in the same manner as these other handlers. The file will typically not be in the default load path of the gem.

I'm not sure the best way to do this. I could take the filename, and then add the containing directory to the load path and then load the file. I could have the user specify a directory containing handlers to be read instead of specifying the file, or I'm sure there are a better way to do it that I haven't yet thought of.

Was it helpful?

Solution

This was fixed using require_relative and expanding the file path using Dir.pwd:

req_path = File.expand_path(arg, Dir.pwd)
require_relative req_path
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top