Obtaining path to file 'require' would load

I’ve been thinking about how one might write a long-running system in Ruby
where there is a requirement to be able to update the definition of some
things while the system is still running.

I know I can use ‘load’ to re-read a file, but for purposes of efficiency, it
would be nice to be able to only re-read it if the file has been modified
since it was last loaded.

Is there already a way to do this? If not, is there a method somewhere that
returns the path to the file that ‘load’ or ‘require’ would process? Ie,
something that scans the library path to find the right one?

Obviously, this would be fairly easy to write, but I’d prefer not to re-invent
the wheel.

This does:
http://rm-f.net/~cout/ruby/treasures/RubyTreasures-0.4/lib/hacks/path_operations.rb.html

You can get the pathname using find_file_in_path(file, $:). You can
then canonicalize it using realpath() – so you don’t require the same
file twice under two different names.

Paul

···

On Thu, Jul 18, 2002 at 07:13:49AM +0900, Harry Ohlsen wrote:

Is there already a way to do this? If not, is there a method somewhere that
returns the path to the file that ‘load’ or ‘require’ would process? Ie,
something that scans the library path to find the right one?