From: "fxn (Xavier Noria) via ruby-core" Date: 2025-05-23T07:31:34+00:00 Subject: [ruby-core:122247] [Ruby Bug#21316] Namespaces leak with permanent names Issue #21316 has been updated by fxn (Xavier Noria). @ko1 yeah, in Ruby you can have two classes with the same permanent name today. You know that, but let me show an example for the archives: ```ruby c = Class.new C = c Object.send(:remove_const, :C) d = Class.new C = d p c.name == d.name # true ``` So, where possible, in arbitrary settings, you better work with class objects. But there are common scenarios (configuration, etc., I described a few above) in which you do not have the object and the natural way to refer to the class is by its name. Today, that is a common practice, and if you want to be able to load arbitrary code within a namespace, I think this has to be preserved. Otherwise, such code won't be loadable under a namespace. ---------------------------------------- Bug #21316: Namespaces leak with permanent names https://bugs.ruby-lang.org/issues/21316#change-113393 * 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/