From 1984f9aedcbb11f0770257eb5ecd4d4f37e0efd5 Mon Sep 17 00:00:00 2001 From: Gannon McGibbon Date: Mon, 15 Apr 2024 10:55:14 -0700 Subject: [PATCH] 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 Co-authored-by: Nobuyoshi Nakada --- load.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/load.c b/load.c index a9c08c62a8..dcf50f5b7a 100644 --- a/load.c +++ b/load.c @@ -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