
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 '<top (required)>': uninitialized constant #<Namespace:24,user,optional>::C (NameError) from /home/eregon/ns.rb:1:in 'Kernel#eval' from /home/eregon/ns.rb:1:in '<top (required)>' from -e:1:in 'Namespace#require' from -e:1:in '<main>' ``` ---------------------------------------- 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/