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

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?


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

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs