From: "matz (Yukihiro Matsumoto)" Date: 2022-10-20T08:21:13+00:00 Subject: [ruby-core:110436] [Ruby master Bug#19067] Module methods not usable at toplevel under wrapped script Issue #19067 has been updated by matz (Yukihiro Matsumoto). `load "foo.rb"` should work (similar enough) with or without wrapping module. In that sense, replacing `self` is unacceptable. Probably you want to get the "target class/module" which is the target of constant/method definitions. I have no idea of notation right now. Matz. ---------------------------------------- Bug #19067: Module methods not usable at toplevel under wrapped script https://bugs.ruby-lang.org/issues/19067#change-99749 * 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. If they cannot, then clarity is needed about what "being executed under" means in the documentation for `load`. See: https://bugs.ruby-lang.org/issues/19024#note-23 -- https://bugs.ruby-lang.org/ Unsubscribe: