From: "shioyama (Chris Salzberg)" Date: 2022-10-18T10:21:24+00:00 Subject: [ruby-core:110390] [Ruby master Bug#19067] Module methods not usable at toplevel under wrapped script Issue #19067 has been updated by shioyama (Chris Salzberg). > As an author of the target file I no longer control the nesting, which is fundamental to know the constant references I am writing are the ones I actually mean. You cannot be sure the constant you are referencing are the ones you mean, ever. I can define "my" `Foo`, then load your file which does something with "your" `Foo`, and your assumptions about `Foo` may be incorrect because of what my `Foo` has in it. If you want to _absolutely_ be sure what a constant is referencing, you would need to disallow `load` altogether. ---------------------------------------- Bug #19067: Module methods not usable at toplevel under wrapped script https://bugs.ruby-lang.org/issues/19067#change-99696 * 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: