Bug #19067
Updated by shioyama (Chris Salzberg) about 2 years ago
```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 about what "being executed under" means in the documentation for `load`.
See: https://bugs.ruby-lang.org/issues/19024#note-23