From: Alex Young Date: 2012-03-19T20:06:26+09:00 Subject: [ruby-core:43467] Re: [ruby-trunk - Feature #4523] Kernel#require to return the path of the loaded file On 18/03/12 10:22, nobu wrote: > > Issue #4523 has been updated by nobu. > > > I don't think it's useful if it may return false. On the contrary - if it returns false, you know the set of loaded files hasn't changed. You (should) know that no new ruby has been parsed. > What's the use case? > I agree that the way to know the loaded path would be useful sometimes, but this doesn't seem nice. The specific thing I was trying to do was gather all the required files into a SQLite database. Then a later process with an overridden `require` can load *precisely* the same file content from that database, without ambiguity. Without this patch, in order to figure out which file was actually loaded, you have to duplicate the $LOAD_PATH file search logic, which is a nasty, hacky duplication of functionality which can break if require's filename resolution logic ever changes. With it, you're guaranteed a correct value. Given that it doesn't break anything (that I know of), and it's such a tiny patch, I honestly don't see a down-side. -- Alex > ---------------------------------------- > Feature #4523: Kernel#require to return the path of the loaded file > https://bugs.ruby-lang.org/issues/4523#change-24910 > > Author: regularfry > Status: Feedback > Priority: Normal > Assignee: > Category: > Target version: > > > =begin > It's very useful to be able to tell which actual file on disc was loaded following a call to require, without having to manually traverse $LOAD_PATH. This information is also not guaranteed to be in $LOADED_FEATURES. > > The attached patch alters rb_require_safe's return value to indicate the loaded file iff a file is actually loaded. > =end > > >