Class: Module

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

Instance Method Summary collapse

Instance Method Details

#autoload(cname, path) ⇒ String

Module/Class level autoload method.

Parameters:

  • cname (#to_sym)

    The constants name.

  • path (String)

    File path to require.

Returns:

  • (String)

    The $AUTOLOAD table.



52
53
54
# File 'lib/autoload.rb', line 52

def autoload(cname, path)
  $AUTOLOAD[[self, cname.to_sym]] << path
end

#const_missing(name) ⇒ Object (private)

Check the $AUTOLOAD table for a ‘[self, name]` entry. If present, require file and try to get the constant again.

Parameters:

  • cname (#to_sym)

    The constants name.



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/autoload.rb', line 67

def const_missing(name)
  if paths = $AUTOLOAD.delete([self, name])
    paths.each do |path|
      require(path)
    end
    const_missing_without_autoload(name) unless const_defined?(name)
    const_get(name)
  else
    const_missing_without_autoload(name)
  end
end

#const_missing_without_autoloadObject (private)



58
# File 'lib/autoload.rb', line 58

alias :const_missing_without_autoload :const_missing