Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created October 3, 2018 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/930fa089aaeb0cb2277eb90aef60e431 to your computer and use it in GitHub Desktop.
Save havenwood/930fa089aaeb0cb2277eb90aef60e431 to your computer and use it in GitHub Desktop.
module Kernel
def require_relative_cthu path
absolute_path = File.absolute_path path, __dir__
realpath = File.realpath "#{absolute_path.chomp '.rb'}.rb"
return false if $LOADED_FEATURES.include? realpath
RubyVM::InstructionSequence.compile_file(realpath).eval
$LOADED_FEATURES << realpath
true
rescue Errno::ENOTDIR, Errno::ENOENT
raise LoadError, "cannot load such file -- #{absolute_path}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment