module Kernel

Patch Kernel to hijack require/require_relative/load/eval

Public Instance Methods

load(path, wrap = false) click to toggle source
# File lib/ruby-next/language/runtime.rb, line 107
def load(path, wrap = false)
  realpath = RubyNext::Language::Runtime.feature_path(path)

  return load_without_ruby_next(path, wrap) unless realpath

  RubyNext::Language::Runtime.load(realpath, wrap: wrap)
rescue => e
  RubyNext.warn "RubyNext failed to load '#{path}': #{e.message}"
  load_without_ruby_next(path)
end
Also aliased as: load_without_ruby_next
load_without_ruby_next(path, wrap = false)
Alias for: load
require(path) click to toggle source
# File lib/ruby-next/language/runtime.rb, line 73
def require(path)
  realpath = RubyNext::Language::Runtime.feature_path(path)
  return require_without_ruby_next(path) unless realpath

  return false if $LOADED_FEATURES.include?(realpath)

  $LOADED_FEATURES << realpath

  RubyNext::Language::Runtime.load(realpath)

  true
rescue => e
  $LOADED_FEATURES.delete realpath
  RubyNext.warn "RubyNext failed to require '#{path}': #{e.message}"
  require_without_ruby_next(path)
end
require_relative(path) click to toggle source
# File lib/ruby-next/language/runtime.rb, line 91
def require_relative(path)
  loc = caller_locations(1..1).first
  from = loc.absolute_path || loc.path || File.join(Dir.pwd, "main")
  realpath = File.absolute_path(
    File.join(
      File.dirname(File.absolute_path(from)),
      path
    )
  )
  require(realpath)
rescue => e
  RubyNext.warn "RubyNext failed to require relative '#{path}' from #{from}: #{e.message}"
  require_relative_without_ruby_next(path)
end
require_relative_without_ruby_next(path)
Alias for: require_relative