From: "fxn (Xavier Noria) via ruby-core" Date: 2025-04-14T14:30:30+00:00 Subject: [ruby-core:121657] [Ruby Misc#21154] Document or change Module#autoload? Issue #21154 has been updated by fxn (Xavier Noria). Hi @mame! > I'm not exactly sure what you meant by "const_get hook", but perhaps you meant "const_added"? I'll assume that's the case and continue. Right, I had a lapsus there. > This means that lib/foo.rb sets autoload :Foo, "lib/foo", which would violate the rule of my documentation patch. Exactly, I could not comply with the new documentation without breaking [hundreds of gems](https://rubygems.org/api/v1/gems/zeitwerk/reverse_dependencies.json). And there are more existing edge cases, I only showed the most important one. Since I know compatibility is something the Ruby team has as a high priority, I believed I had to raise this concern. And, besides these examples, code issuing dynamic autoloads cannot comply with the docs either, because it has no way to check if a given file is being loaded at the moment. But this point is kind of more theoretical, while the point above is very real. > By the way, I appreciate your kindness in recording a video, but to be honest, I'm not very good at understanding spoken English. I'd appreciate it if you could explain things in text and using code examples. My pleasure. I'll remember that for other tickets. Regarding your remarks about loading the entrypoint by passing it to the interpreter, or to `Kernel#load`, etc. these are [documented](https://github.com/fxn/zeitwerk?tab=readme-ov-file#for_gem) to not be supported: *"Due to technical reasons, the entry point of the gem has to be loaded with Kernel#require, which is the standard way to load a gem. Loading that file with Kernel#load or Kernel#require_relative won't generally work."* > I think I understand the problem and can explain it at the May dev meeting. However, I am not sure what is the best solution for this issue. Excellent, thank you. The discussion here was related to the predicate `Module#autoload?`, I guess you guys ended up addressing this one by disallowing circularity altogether, but (as you mentioned in some comment), that turns to uncover stuff that perhaps was not foreseen during the discussion. May I suggest restoring the original documentation? Thanks again, hope you folks have a great time in RubyKaigi. ---------------------------------------- Misc #21154: Document or change Module#autoload? https://bugs.ruby-lang.org/issues/21154#change-112712 * Author: fxn (Xavier Noria) * Status: Feedback * Assignee: mame (Yusuke Endoh) ---------------------------------------- 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/