[ruby-core:124340] [Ruby Bug#21799] Delegated top-level methods are not visible outside the Ruby Box
Issue #21799 has been reported by koic (Koichi ITO). ---------------------------------------- Bug #21799: Delegated top-level methods are not visible outside the Ruby Box https://bugs.ruby-lang.org/issues/21799 * Author: koic (Koichi ITO) * Status: Open * ruby -v: ruby 4.0.0dev (2025-12-21T19:08:00Z master cfb324e9d1) +PRISM [arm64-darwin24] * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- The following example code based on Ruby Box results in an unexpected error. https://github.com/ruby/ruby/blob/v4.0.0-preview3/doc/language/box.md#top-le... I'm not familiar with Ruby Box, but it seems that either the above documentation example in doc/language/box.md or the Ruby Box implementation is incorrect. ## Steps to reproduce ```console $ cat main.rb box = Ruby::Box.new box.require_relative('foo') p box.Foo.say #=> "foo" p yay # NoMethodError ``` ```console $ cat foo.rb def yay = "foo" class Foo def self.say = yay end p Foo.say #=> "foo" p yay #=> "foo" ``` ## Expected According to the documentation example, `box.Foo.say` in `main.rb` should return the string `"foo"`. ## Actual Contrary to the documentation example, calling `box.Foo.say` in `main.rb` raises a `NoMethodError`. ```console $ RUBY_BOX=1 ruby main.rb ruby: warning: Ruby::Box is experimental, and the behavior may change in the future! See doc/language/box.md for known issues, etc. "foo" "foo" main.rb:4:in '<main>': undefined method 'Foo' for module #<Ruby::Box:3,user,optional> (NoMethodError) p box.Foo.say #=> "foo" ^^^^ ``` ## Additional Information According to the description below, the documentation example might not be appropriate, but it's unclear what visibility delegated top-level methods have.
Currently, top level methods in boxes are not accessible from outside of the box. But there might be a use case to call other box's top level methods.
https://github.com/ruby/ruby/blob/v4.0.0-preview3/doc/language/box.md#expose... -- https://bugs.ruby-lang.org/
Issue #21799 has been updated by jeremyevans0 (Jeremy Evans). I think `box.Foo.say` should be `box::Foo.say`. https://github.com/ruby/ruby/pull/15690 ---------------------------------------- Bug #21799: Delegated top-level methods are not visible outside the Ruby Box https://bugs.ruby-lang.org/issues/21799#change-115846 * Author: koic (Koichi ITO) * Status: Open * ruby -v: ruby 4.0.0dev (2025-12-21T19:08:00Z master cfb324e9d1) +PRISM [arm64-darwin24] * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- The following example code based on Ruby Box results in an unexpected error. https://github.com/ruby/ruby/blob/v4.0.0-preview3/doc/language/box.md#top-le... I'm not familiar with Ruby Box, but it seems that either the above documentation example in doc/language/box.md or the Ruby Box implementation is incorrect. ## Steps to reproduce ```console $ cat main.rb box = Ruby::Box.new box.require_relative('foo') p box.Foo.say #=> "foo" p yay # NoMethodError ``` ```console $ cat foo.rb def yay = "foo" class Foo def self.say = yay end p Foo.say #=> "foo" p yay #=> "foo" ``` ## Expected According to the documentation example, `box.Foo.say` in `main.rb` should return the string `"foo"`. ## Actual Contrary to the documentation example, calling `box.Foo.say` in `main.rb` raises a `NoMethodError`. ```console $ RUBY_BOX=1 ruby main.rb ruby: warning: Ruby::Box is experimental, and the behavior may change in the future! See doc/language/box.md for known issues, etc. "foo" "foo" main.rb:4:in '<main>': undefined method 'Foo' for module #<Ruby::Box:3,user,optional> (NoMethodError) p box.Foo.say #=> "foo" ^^^^ ``` ## Additional Information According to the description below, the documentation example might not be appropriate, but it's unclear what visibility delegated top-level methods have.
Currently, top level methods in boxes are not accessible from outside of the box. But there might be a use case to call other box's top level methods.
https://github.com/ruby/ruby/blob/v4.0.0-preview3/doc/language/box.md#expose... -- https://bugs.ruby-lang.org/
Issue #21799 has been updated by byroot (Jean Boussier). Status changed from Open to Closed Yes. `Foo` is a constant, not a method. The example was wrong. Now that it's updated we can close. ---------------------------------------- Bug #21799: Delegated top-level methods are not visible outside the Ruby Box https://bugs.ruby-lang.org/issues/21799#change-115859 * Author: koic (Koichi ITO) * Status: Closed * ruby -v: ruby 4.0.0dev (2025-12-21T19:08:00Z master cfb324e9d1) +PRISM [arm64-darwin24] * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- The following example code based on Ruby Box results in an unexpected error. https://github.com/ruby/ruby/blob/v4.0.0-preview3/doc/language/box.md#top-le... I'm not familiar with Ruby Box, but it seems that either the above documentation example in doc/language/box.md or the Ruby Box implementation is incorrect. ## Steps to reproduce ```ruby # main.rb box = Ruby::Box.new box.require_relative('foo') p box.Foo.say #=> "foo" p yay # NoMethodError ``` ```ruby # foo.rb def yay = "foo" class Foo def self.say = yay end p Foo.say #=> "foo" p yay #=> "foo" ``` ## Expected According to the documentation example, `box.Foo.say` in `main.rb` should return the string `"foo"`. ## Actual Contrary to the documentation example, calling `box.Foo.say` in `main.rb` raises a `NoMethodError`. ```console $ RUBY_BOX=1 ruby main.rb ruby: warning: Ruby::Box is experimental, and the behavior may change in the future! See doc/language/box.md for known issues, etc. "foo" "foo" main.rb:4:in '<main>': undefined method 'Foo' for module #<Ruby::Box:3,user,optional> (NoMethodError) p box.Foo.say #=> "foo" ^^^^ ``` ## Additional Information According to the description below, the documentation example might not be appropriate, but it's unclear what visibility delegated top-level methods have.
Currently, top level methods in boxes are not accessible from outside of the box. But there might be a use case to call other box's top level methods.
https://github.com/ruby/ruby/blob/v4.0.0-preview3/doc/language/box.md#expose... -- https://bugs.ruby-lang.org/
participants (3)
-
byroot (Jean Boussier) -
jeremyevans0 (Jeremy Evans) -
koic (Koichi ITO)