In ruby code, how would I check what external libraries are loaded? For example,
require 'some-library'
if is-loaded?('some-library')
puts "this will run"
end
or
# require 'some-library' Don't load it in here
if is-loaded?('some-library')
puts "this will not run"
end
Is there a way to do this?
Note on why I need this:
I’m working on boom, and on windows, it will try to include ‘Win32/Console/ANSI’, to enable ANSI color codes like \e[36m. What I’m trying to do is if the system is windows and ‘Win32/Console/ANSI’ is not loaded, it would append the color codes, so the color codes are not outputted. Here is the file.
Most libraries will typically define a top-level constant. The usual thing to do is to check whether that constant is defined.