From: "Eregon (Benoit Daloze) via ruby-core" Date: 2025-05-10T12:13:34+00:00 Subject: [ruby-core:121983] [Ruby Bug#21316] Namespaces leak with permanent names Issue #21316 has been updated by Eregon (Benoit Daloze). Right I think in the namespace defining the class/module the `Module#name` needs to not have a prefix, or it will break many gems. OTOH when used outside, it could be very confusing without a prefix. > suggested that Class#name should behave as follows: Yeah, that's probably the best trade-off, although of course it means the Module#name for a given Module changes based on which Namespace is the current one. --- BTW, I think the main namespace constants should also be prefixed when seen in another namespace, currently it's not the case: ``` $ RUBY_NAMESPACE=1 ruby -ve 'main = Namespace.current; ns = Namespace.new; class C; end; ns::MAIN_C = C; File.write "ns.rb", "p MAIN_C; p eval(MAIN_C.name)"; ns.require "./ns"' ruby 3.5.0dev (2025-05-10T07:50:29Z namespace-on-read-.. bd4f57f96b) +PRISM [x86_64-linux] ruby: warning: Namespace is experimental, and the behavior may change in the future! See doc/namespace.md for know issues, etc. C (eval at /home/eregon/ns.rb:1):1:in '': uninitialized constant #::C (NameError) from /home/eregon/ns.rb:1:in 'Kernel#eval' from /home/eregon/ns.rb:1:in '' from -e:1:in 'Namespace#require' from -e:1:in '
' ``` ---------------------------------------- Bug #21316: Namespaces leak with permanent names https://bugs.ruby-lang.org/issues/21316#change-113099 * Author: fxn (Xavier Noria) * Status: Open * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- Namespaces are not transparent for this program ```ruby C = Class.new C.name == 'C' ``` because under a non-main user namespace, the name of `C` has the namespace as a prefix. -- 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/