If I see a require
in source code.
require "blah"
How do I determine if that library ("blah") was provided by the core ruby installation or if it came from the installation of a gem?
You can read the $LOADED_FEATURES
and check if path came from gem or not, which means that you are testing if the feature belongs to the core installation or not.
# return true if library is an external gem
$LOADED_FEATURES.grep(/library/).grep(/gems/).size > 0
Once require
has found an loaded a library file it adds the full path to that file to the $LOADED_FEATURES
array. So you could look in that array to see where it found blah
$LOADED_FEATURES.find_all { |path| puts path if /blah/ =~ path }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With