From: "fxn (Xavier Noria) via ruby-core" Date: 2025-02-25T10:33:38+00:00 Subject: [ruby-core:121159] [Ruby master Misc#21154] Document or change Module#autoload? Issue #21154 has been updated by fxn (Xavier Noria). Hi @mame, thank for your reply. > No, not necessarily. The document says "if name is registered as autoload". And the document of Kernel#autoload says "If const is defined but not as autoload, does nothing." Thus, there is no guarantee that your second line will always return "foo". That is right. However, if we have a file `foo.rb` ```ruby autoload :Foo, 'foo' p autoload?(:Foo) ``` That prints `nil` if you `ruby -I. -e 'require "foo"'`. So, the constant is not defined, the autoload is registered, and you get `nil`. This does not agree with the documentation, do you agree? You may say "circularity!". And I'll say, cool, but undocumented. > I think what you should do is not arguing about consistency with the documentation, but rather briefly explaining your purpose and why the current behavior is troubling against it. I am not arguing, I believe my tickets cannot be more respectful, formulated as questions, and leaving the door open to an explanation of how things work that is not documented. You do not always come to ask for questions with a use case in mind. I do use `autoload?` and this edge case affects me, yes. But what I am trying to accomplish is know Ruby better. I understand you don't want to documente this (we disagree, but that is your call), but you also have to understand that as a Ruby programmer I strive to understand how Ruby works per se, that is my goal. And not being a committer, I cannot by myself know if the mismatches with the docs are intentional, an overlook, or if intentional, which is the mental model that fits that mismatch. ---------------------------------------- Misc #21154: Document or change Module#autoload? https://bugs.ruby-lang.org/issues/21154#change-112099 * Author: fxn (Xavier Noria) * Status: Open ---------------------------------------- The documentation of `Module#autoload?` says > Returns filename to be loaded if name is registered as autoload in the namespace of mod or one of its ancestors. Cool, but in the following snippet ```ruby autoload :Foo, 'foo' autoload?(:Foo) ``` the second line could evaluate to `nil`, and this does not seem to agree. I just registered an autoload, therefore (according to the documentation) I should get "foo" back in line 2. I'd like to ask for clarification from the Ruby team: 1. Is the documentation complete? Should that second line always return "foo"? 2. If the answer is no, which is the logic missing in the docs? Thank you! -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/