From: "shioyama (Chris Salzberg)" Date: 2022-09-23T01:25:40+00:00 Subject: [ruby-core:110021] [Ruby master Bug#18960] Module#using raises RuntimeError when called at toplevel from wrapped script Issue #18960 has been updated by shioyama (Chris Salzberg). Hmm, ok this is where the problem happens without the patch: https://github.com/shioyama/rails/blob/b9493a47e65287f3b135904dbdd511bbf5a5798c/activesupport/lib/active_support/core_ext/enumerable.rb#L285-L291 ```ruby # Using Refinements here in order not to expose our internal method using Module.new { refine Array do alias :orig_sum :sum end } ``` Although this is somewhat contrived, you can reproduce the problem on the same file as follows: ```ruby mod = Module.new mod::Enumerable = Enumerable load $LOAD_PATH.resolve_feature_path("active_support/core_ext/enumerable")[1], mod # main.using is permitted only at toplevel (RuntimeError) ``` ---------------------------------------- Bug #18960: Module#using raises RuntimeError when called at toplevel from wrapped script https://bugs.ruby-lang.org/issues/18960#change-99272 * Author: shioyama (Chris Salzberg) * Status: Open * Priority: Normal * ruby -v: 3.1.2p20 * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- I noticed that this file works when loaded with `load`, but fails if you pass `true` (or a module) as the `wrap` argument. ```ruby # using.rb using Module.new ``` This works: ```ruby load "./using.rb" ``` This doesn't: ```ruby load "./using.rb", true # raises RuntimeError (main.using is permitted only at toplevel) ``` I believe the latter should work. -- https://bugs.ruby-lang.org/ Unsubscribe: