Perhaps you want to play around with $LOADED_FEATURES
(alias of $"
), that array that contains the module names
loaded by require
?
def was_required?(file)
rex = Regexp.new("/#{Regexp.quote(file)}\.(so|o|sl|rb)?")
$LOADED_FEATURES.find { |f| f =~ rex }
end
was_required?('uri')
#=> false
require 'uri'
#=> true
was_required?('uri')
#=> true
Btw this is exactly what Ruby does in the require
method.