From: "shioyama (Chris Salzberg)" Date: 2022-10-18T11:11:39+00:00 Subject: [ruby-core:110395] [Ruby master Bug#19067] Module methods not usable at toplevel under wrapped script Issue #19067 has been updated by shioyama (Chris Salzberg). > This is a bit incompatible, but I wonder if it is better than dealing with `Module#using`, `Module#private_method`, etc. individually. Yes, and to be honest, I didn't realize how much failed to work as "expected" until after I had created this issue. Still, I think this is worth thinking about. Previously, it was not possible to control the module to `load`, so this was not really an issue. But now it is. And I do think it's slightly ambiguous what is supposed to happen here. e.g. ```ruby # foo.rb require "my_dependency" ... code that depends on my_dependency ``` ```ruby module MyModule def require(filename) puts "required #{filename}!" end end load "./foo.rb", MyModule #=> required my_dependency! ``` In this case, because `top_self` extends the `wrap` module, `require` is (re-)defined and `foo.rb` does not actually require its dependency. This is interesting, but I don't think it was the original intention of extending `top_self` with the `wrap` module. ---------------------------------------- Bug #19067: Module methods not usable at toplevel under wrapped script https://bugs.ruby-lang.org/issues/19067#change-99702 * Author: shioyama (Chris Salzberg) * Status: Open * Priority: Normal * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- ```ruby #foo.rb module Foo end private_constant :Foo ``` ```ruby module MyModule; end load "./foo.rb", MyModule # undefined method `private_constant' for main:Object (NoMethodError) # # private_constant :Foo # ^^^^^^^^^^^^^^^^ # Did you mean? private_methods ``` However, this works: ```ruby module MyModule module Foo end private_constant :Foo end ``` `load` loads the code under the `wrap` module, so this seems like a bug to me. This applies to all methods on `Module`, which are usable inside a normal module definition but not usable when the module is the `wrap` argument to `load`. I think these should all be usable in this context. See: https://bugs.ruby-lang.org/issues/19024#note-23 -- https://bugs.ruby-lang.org/ Unsubscribe: