Viewing a script source loaded into the interpreter

I’ve read about the SCRIPT_LINES__ hash being able hold the contents of
a script in the interpreter, if it were loaded via “require”.

But, I’m not certain that all loaded (“required”) scripts get saved in
SCRIPT_LINES__.

Would the SCRIPT_LINES__ hash contain files that were required via the
API in rb_require()?

Also, is there anyway to access the script source, from within ruby, if
the script was loaded via rb_load_file()?

Or, in other words… once a script is loaded, no matter how, can that
source be extracted? If so, how?

Thanks.

i thought you joked because i test it…

require “gosu”
p SCRIPT_LINES__ #undefined constant

but it only works if SCRIPT_LINES__ is defined before require

SCRIPT_LINES__ = {}
require “gosu”
p SCRIPT_LINES__ #many lines

but i think SCRIPT_LINES__ is very ugly and i do not like it

PS: no you does not get all code, because some stuff you require is
written in C or C++

I believe it also does not work for ruby scripts loaded via the
embedding program’s calls to the API.