Feature #6210
closedload should provide a way to specify the top-level module
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 12 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 12 years ago
- Status changed from Open to Assigned
Updated by ko1 (Koichi Sasada) almost 12 years ago
- Target version changed from 2.0.0 to 2.6
I changed target to next minor because no discussion on it.
Updated by jeremyevans0 (Jeremy Evans) almost 3 years 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) almost 3 years 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) almost 3 years ago
OK, I (finally) accepted the proposal. Go ahead.
Matz.
Updated by jeremyevans (Jeremy Evans) almost 3 years 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) almost 3 years ago
What about the RubyVM::InstructionSequence
was there any discussion to allow caching Kernel.load(path, module_instance)
?
Updated by jeremyevans0 (Jeremy Evans) almost 3 years ago
byroot (Jean Boussier) wrote in #note-9:
What about the
RubyVM::InstructionSequence
was there any discussion to allow cachingKernel.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?