The require method in ruby will search the lib_path and load the first matching files found if needed. Is there anyway to print the path to the file which would be loaded. I’m looking for, ideally built-in, functionality similar to the which command in bash and hoping it can be that simple too. Thanks.
The require method in ruby will search the lib_path and load the first matching
Share
I don’t know of a built-in functionality, but defining your own isn’t hard. Here’s a solution adapted from this question:
Explanation:
$:is a pre-defined variable. It’s an array of places to search for files you canloadorrequire. Thewhichmethod iterates through each path looking for the file you called it on. If it finds a match, it returns the file path.I’m assuming you just want the output to be a single line showing the full filepath of the
requiredfile, likewhich. If you want to also see the files yourrequiredfile will load itself, something like the solution in the linked question might be more appropriate: