Method: Kernel#load

Defined in:
lib/onload/core_ext/kernel_zeitwerk.rb

#load(file, *args) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/onload/core_ext/kernel_zeitwerk.rb', line 9

def load(file, *args)
  if Onload.process?(file) && Onload.enabled?
    f = Onload::File.new(file)
    f.write

    # I don't understand why, but it's necessary to delete the constant
    # in order to load the resulting file. Otherwise you get an error about
    # an uninitialized constant, and it's like... yeah, I _know_ it's
    # uninitialized, that's why I'm loading this file. Whatevs.
    loader = if Zeitwerk::Registry.respond_to?(:loader_for)
      Zeitwerk::Registry.loader_for(file)
    else
      Zeitwerk::Registry.autoloads.registered?(file)
    end

    parent, cname = loader.send(:autoloads)[file]

    if defined?(Zeitwerk::Cref) && parent.is_a?(Zeitwerk::Cref)
      parent.remove
    else
      parent.send(:remove_const, cname)
    end

    return onload_orig_load(f.outfile, *args)
  end

  onload_orig_load(file, *args)
end