Specify Kernel#autoload? uses current namespace

Because Kernel#autoload? uses the current namespace, it can lead to
potentially confusing results. We should make it clearer that modules
count as separate namespaces to lookup in.

Co-authored-by: Jeremy Evans <code@jeremyevans.net>
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
This commit is contained in:
Gannon McGibbon 2024-04-15 10:55:14 -07:00 committed by GitHub
parent 733d50f0a5
commit 1984f9aedc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

14
load.c
View File

@ -1532,10 +1532,22 @@ rb_f_autoload(VALUE obj, VALUE sym, VALUE file)
* autoload?(name, inherit=true) -> String or nil
*
* Returns _filename_ to be loaded if _name_ is registered as
* +autoload+.
* +autoload+ in the current namespace or one of its ancestors.
*
* autoload(:B, "b")
* autoload?(:B) #=> "b"
*
* module C
* autoload(:D, "d")
* autoload?(:D) #=> "d"
* autoload?(:B) #=> nil
* end
*
* class E
* autoload(:F, "f")
* autoload?(:F) #=> "f"
* autoload?(:B) #=> "b"
* end
*/
static VALUE