Class: Module

Inherits:
Object
  • Object
show all
Defined in:
lib/capsule/autoimport.rb

Direct Known Subclasses

Capsule

Instance Method Summary collapse

Instance Method Details

#autoimportObject

When the constant named by symbol mod is referenced, loads the script in filename using Capsule.load and defines the constant to be equal to the resulting Capsule module.

Use like Module#autoload–however, the underlying opertation is #load rather than #require, because scripts, unlike libraries, can be loaded more than once. See examples/autoscript-example.rb



27
28
29
30
31
32
# File 'lib/capsule/autoimport.rb', line 27

define_method(:autoimport) do |mod, file|
  if @autoimport.empty? #unless $autoimport_activated
    const_missing_definition_for_autoimport.call
  end
  (@autoimport ||= {})[mod] = file
end