Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Explicit imports for Ruby on a per-class/module basis
branch: master

Merge pull request #1 from gilesbowkett/master

quasi-typo: stray backslash
latest commit b9ed1aa74f
Gary Bernhardt authored
Failed to load latest commit information.
lib rename variable
spec add submodule importing stray backslash



This module adds explicit imports to Ruby. By calling the import method during class or module definition, all constants in the module's namespace will be replaced by placeholders, except a few core types and those that are explicitly imported. For example, in this class:

class Joe
  import 'File'

  def file_exists?(path)

  def create_queue

the File module will be available:

=> true

But other constants, like Queue, won't be:

NoMethodError: undefined method `new' for #<ExplicitImport::CantTouchThis:0x10135a8c0>

As you can see, the constants are present, but have placeholder values:

>> Joe.const_get(:Queue)
=> #<ExplicitImport::CantTouchThis:0x10135a8c0>

That's unfortunate. I have an idea about how to make them actually throw a NameError, though it's pretty evil.


Minimal. You almost certainly don't want to use this as it exists right now. For one thing, it only isolates the module from constants defined before the module itself; subsequent constant definitions will be missed.

There are probably ways to fix that. Patches are welcome if this kind of thing tickles your fancy.

Something went wrong with that request. Please try again.