
Issue #21316 has been updated by make_now_just (Hiroya Fujinami). I found an issue on `Marshal` and `Namespace` maybe related to this ticket. When dumping an object defined in a namespace using Marshal, the result will vary depending on whether the namespace is held as a variable or constant, and whether `Marshal.dump` is performed inside or outside the namespace. In other words, we have the following files: `ns.rb`: ```ruby class Foo def dump_in_ns = Marshal.dump(self) end ``` `main.rb`: ```ruby ns = Namespace.new ns.require("./ns.rb") NS = Namespace.new NS.require("./ns.rb") puts "var / in ns" begin ns::Foo.new.dump p :ok rescue => ex p :error p ex end puts puts "const / in ns" begin NS::Foo.new.dump p :ok rescue => ex p :error p ex end puts puts "var / out ns" begin Marshal.dump(ns::Foo.new) p :ok rescue => ex p :error p ex end puts puts "const / out ns" begin Marshal.dump(NS::Foo.new) p :ok rescue => ex p :error p ex end ``` Then, the result is as follows: ```console $ RUBY_NAMESPACE=1 ruby main.rb var / in ns :error #<NoMethodError: undefined method 'dump' for an instance of #<Namespace:0x000000012018ed88>::Foo> const / in ns :error #<NoMethodError: undefined method 'dump' for an instance of NS::Foo> var / out ns :error #<TypeError: can't dump anonymous class #<Namespace:0x000000012018ed88>::Foo> const / out ns :ok ``` I'm not sure this issue is completely related to this ticket, but `Marshal.dump` should work in any case. ---------------------------------------- Bug #21316: Namespaces leak with permanent names https://bugs.ruby-lang.org/issues/21316#change-113195 * 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/