[ruby-core:122240] [Ruby Bug#21363] `Namespace.current` should always return the Namespace in which it was defined
Issue #21363 has been reported by tenderlovemaking (Aaron Patterson). ---------------------------------------- Bug #21363: `Namespace.current` should always return the Namespace in which it was defined https://bugs.ruby-lang.org/issues/21363 * Author: tenderlovemaking (Aaron Patterson) * Status: Open * ruby -v: ruby 3.5.0dev (2025-05-22T23:07:21Z rm-assertion 17e71c7a24) +PRISM [arm64-darwin24] * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- I think `Namespace.current` should always return the namespace in which it was defined. Here is an example to demonstrate what I mean: ```ruby File.binwrite("ns.rb", <<-RUBY) # namespace 3 module M def self.test p Namespace.current end TEST = -> { p Namespace.current } end RUBY ns = Namespace.new ns.load "./ns.rb" p Namespace.current ns::M.test ns::M::TEST.call ``` I expect the output of `ns::M.test` and `ns::M::TEST.call` to be the same. Instead the output is like this: ``` #<Namespace:2,user,main> #<Namespace:3,user,optional> #<Namespace:2,user,main> ``` I think a method and lambda defined in the same namespace should return the same value for `Namespace.current` -- https://bugs.ruby-lang.org/
Issue #21363 has been updated by tenderlovemaking (Aaron Patterson). To be more specific, given this program: ```ruby File.binwrite("ns.rb", <<-RUBY) # namespace 3 module M def self.test p test: Namespace.current end TEST = -> { p lambda: Namespace.current } end RUBY ns = Namespace.new ns.load "./ns.rb" p main: Namespace.current ns::M.test ns::M::TEST.call ``` I expect the following output: ``` {main: #<Namespace:2,user,main>} {test: #<Namespace:3,user,optional>} {lambda: #<Namespace:3,user,optional>} ``` But I got the following output: ``` {main: #<Namespace:2,user,main>} {test: #<Namespace:3,user,optional>} {lambda: #<Namespace:2,user,main>} ``` ---------------------------------------- Bug #21363: `Namespace.current` should always return the Namespace in which it was defined https://bugs.ruby-lang.org/issues/21363#change-113402 * Author: tenderlovemaking (Aaron Patterson) * Status: Open * ruby -v: ruby 3.5.0dev (2025-05-22T23:07:21Z rm-assertion 17e71c7a24) +PRISM [arm64-darwin24] * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- I think `Namespace.current` should always return the namespace in which it was defined. Here is an example to demonstrate what I mean: ```ruby File.binwrite("ns.rb", <<-RUBY) # namespace 3 module M def self.test p Namespace.current end TEST = -> { p Namespace.current } end RUBY ns = Namespace.new ns.load "./ns.rb" p Namespace.current ns::M.test ns::M::TEST.call ``` I expect the output of `ns::M.test` and `ns::M::TEST.call` to be the same. Instead the output is like this: ``` #<Namespace:2,user,main> #<Namespace:3,user,optional> #<Namespace:2,user,main> ``` I think a method and lambda defined in the same namespace should return the same value for `Namespace.current` -- https://bugs.ruby-lang.org/
Issue #21363 has been updated by tagomoris (Satoshi Tagomori). Assignee set to tagomoris (Satoshi Tagomori) ---------------------------------------- Bug #21363: `Namespace.current` should always return the Namespace in which it was defined https://bugs.ruby-lang.org/issues/21363#change-115540 * Author: tenderlovemaking (Aaron Patterson) * Status: Open * Assignee: tagomoris (Satoshi Tagomori) * ruby -v: ruby 3.5.0dev (2025-05-22T23:07:21Z rm-assertion 17e71c7a24) +PRISM [arm64-darwin24] * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- I think `Namespace.current` should always return the namespace in which it was defined. Here is an example to demonstrate what I mean: ```ruby File.binwrite("ns.rb", <<-RUBY) # namespace 3 module M def self.test p Namespace.current end TEST = -> { p Namespace.current } end RUBY ns = Namespace.new ns.load "./ns.rb" p Namespace.current ns::M.test ns::M::TEST.call ``` I expect the output of `ns::M.test` and `ns::M::TEST.call` to be the same. Instead the output is like this: ``` #<Namespace:2,user,main> #<Namespace:3,user,optional> #<Namespace:2,user,main> ``` I think a method and lambda defined in the same namespace should return the same value for `Namespace.current` -- https://bugs.ruby-lang.org/
Issue #21363 has been updated by tagomoris (Satoshi Tagomori). Status changed from Open to Closed Now it's working as we expects: ``` MBA:build s-tagomori$ cat m.rb module M def self.test p test: Ruby::Box.current end TEST = -> { p lambda: Ruby::Box.current } end MBA:build s-tagomori$ RUBY_BOX=1 ./exe/ruby -e 'b = Ruby::Box.new; b.require("./m"); p main: Ruby::Box.current; b::M.test; b::M::TEST.call' ./exe/ruby: warning: Ruby::Box is experimental, and the behavior may change in the future! See doc/language/box.md for known issues, etc. {main: #<Namespace:2,user,main>} {test: #<Namespace:3,user,optional>} {lambda: #<Namespace:3,user,optional>} MBA:build s-tagomori$ ./exe/ruby -v ruby 4.0.0dev (2025-12-09T12:29:36Z box-news-documents.. c998717de8) +PRISM [arm64-darwin24] ``` ---------------------------------------- Bug #21363: `Namespace.current` should always return the Namespace in which it was defined https://bugs.ruby-lang.org/issues/21363#change-115546 * Author: tenderlovemaking (Aaron Patterson) * Status: Closed * Assignee: tagomoris (Satoshi Tagomori) * ruby -v: ruby 3.5.0dev (2025-05-22T23:07:21Z rm-assertion 17e71c7a24) +PRISM [arm64-darwin24] * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- I think `Namespace.current` should always return the namespace in which it was defined. Here is an example to demonstrate what I mean: ```ruby File.binwrite("ns.rb", <<-RUBY) # namespace 3 module M def self.test p Namespace.current end TEST = -> { p Namespace.current } end RUBY ns = Namespace.new ns.load "./ns.rb" p Namespace.current ns::M.test ns::M::TEST.call ``` I expect the output of `ns::M.test` and `ns::M::TEST.call` to be the same. Instead the output is like this: ``` #<Namespace:2,user,main> #<Namespace:3,user,optional> #<Namespace:2,user,main> ``` I think a method and lambda defined in the same namespace should return the same value for `Namespace.current` -- https://bugs.ruby-lang.org/
participants (2)
-
tagomoris (Satoshi Tagomori) -
tenderlovemaking (Aaron Patterson)