Module: Kernel

Defined in:
lib/derailed_benchmarks/core_ext/kernel_require.rb

Overview

Monkey patch kernel to ensure that all ‘require` calls call the same method

Constant Summary collapse

REQUIRE_STACK =
[]

Class Method Summary collapse

Class Method Details

.load(file, wrap = false) ⇒ Object



22
23
24
25
26
# File 'lib/derailed_benchmarks/core_ext/kernel_require.rb', line 22

def load(file, wrap = false)
  measure_memory_impact(file) do |file|
    original_load(file)
  end
end

.original_loadObject



20
# File 'lib/derailed_benchmarks/core_ext/kernel_require.rb', line 20

alias_method(:original_load, :load)

.original_requireObject



18
# File 'lib/derailed_benchmarks/core_ext/kernel_require.rb', line 18

alias_method :original_require, :require

.original_require_relativeObject



19
# File 'lib/derailed_benchmarks/core_ext/kernel_require.rb', line 19

alias_method :original_require_relative, :require_relative

.require(file) ⇒ Object



28
29
30
31
32
# File 'lib/derailed_benchmarks/core_ext/kernel_require.rb', line 28

def require(file)
  measure_memory_impact(file) do |file|
    original_require(file)
  end
end

.require_relative(file) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/derailed_benchmarks/core_ext/kernel_require.rb', line 34

def require_relative(file)
  if Pathname.new(file).absolute?
    require file
  else
    require File.expand_path("../#{file}", caller_locations(1, 1)[0].absolute_path)
  end
end