1 min read

TIL: Ruby Knows the Source of Required Code

There's a magic variable which, if initialised, will contain the source of all the files imported afterwards

There's a magic variable which, if initialised, will contain the source of all the files imported afterwards.

SCRIPT_LINES__ = {}
require 'something'
# {"something.rb" => ["line 1", "line 2", ...]