Module: Monkey::Autoloader

Defined in:
lib/monkey/autoloader.rb

Instance Method Summary collapse

Instance Method Details

#const_missing(const_name) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/monkey/autoloader.rb', line 22

def const_missing(const_name)
  const_name = const_name.to_s
  file = File.join(self.name.to_const_path, const_name.to_const_path)
  begin
    require file
    if const_defined? const_name
      const = const_get const_name
      const.extend Monkey::Autoloader
      const
    else
      warn "expected #{file} to define #{name}::#{const_name}"
      raise LoadError
    end
  rescue LoadError => error
    begin
      return parent.const_get(const_name) if respond_to? :parent and parent != self
    rescue NameError
    end
    warn "tried to load #{file}: #{error.message}"
    super
  end
end