Project

General

Profile

Actions

Feature #6210

closed

load should provide a way to specify the top-level module

Added by now (Nikolai Weibull) over 10 years ago. Updated 10 months ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:43774]

Description

load currently takes an optional second argument that allows you to load into an anonymous and new top-level Module. It would be nice if the second argument could also be a Module that would then be used as the top-level Module. That way one could provide a set of methods that should be available to the content being loaded without having to put them in Kernel.

Updated by luislavena (Luis Lavena) over 10 years ago

  • Assignee set to matz (Yukihiro Matsumoto)
  • Target version set to 2.0.0

Sounds partially like #5643?

Updated by mame (Yusuke Endoh) over 10 years ago

  • Status changed from Open to Assigned

Updated by ko1 (Koichi Sasada) almost 10 years ago

  • Target version changed from 2.0.0 to 2.6

I changed target to next minor because no discussion on it.

Actions #4

Updated by naruse (Yui NARUSE) almost 5 years ago

  • Target version deleted (2.6)

Updated by jeremyevans0 (Jeremy Evans) 11 months ago

I think this is a useful feature, and it can be implemented without any API changes/backwards compatibility issues. I submitted a pull request for it: https://github.com/ruby/ruby/pull/4986

Updated by byroot (Jean Boussier) 11 months ago

Agreed, it could be used to experiment with new ways to load code in a non global manner.

That being said it would entirely sidestep iseq caching. Not that it's a deal breaker, but if this were to be used for loading lots of code, we might also need RubyVM::InstructionSequence#eval(wrapping_module)

Updated by matz (Yukihiro Matsumoto) 10 months ago

OK, I (finally) accepted the proposal. Go ahead.

Matz.

Actions #8

Updated by jeremyevans (Jeremy Evans) 10 months ago

  • Status changed from Assigned to Closed

Applied in changeset git|b35b7a1ef25347735a6bb7c28ab7e77afea1d856.


Allow Kernel#load to load code into a specified module

Instead of always using a new anonymous module for Kernel#load if
the wrap argument is not false/nil, use the given module if a module
is provided.

Implements [Feature #6210]

Updated by byroot (Jean Boussier) 10 months ago

What about the RubyVM::InstructionSequence was there any discussion to allow caching Kernel.load(path, module_instance)?

Updated by jeremyevans0 (Jeremy Evans) 10 months ago

byroot (Jean Boussier) wrote in #note-9:

What about the RubyVM::InstructionSequence was there any discussion to allow caching Kernel.load(path, module_instance)?

The dev meeting log does not indicate this was discussed. If you think it's important, can you add it as a new feature request?

Actions

Also available in: Atom PDF