Project

General

Profile

Actions

Bug #19067

closed

Module methods not usable at toplevel under wrapped script

Added by shioyama (Chris Salzberg) about 2 years ago. Updated about 2 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:110378]

Description

#foo.rb 
module Foo
end
private_constant :Foo
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:

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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0