class Backports::StdLib::LoadedFeatures

Public Class Methods

mark_as_loaded(feature) click to toggle source
# File lib/backports/tools/std_lib.rb, line 20
def self.mark_as_loaded(feature)
  @@our_loads[feature] = true
  # Nothing to do, the full path will be OK
end

Public Instance Methods

include?(feature) click to toggle source

Check loaded features for one that matches “#{any of the load path}/#{feature}”

# File lib/backports/tools/std_lib.rb, line 8
def include?(feature)
  return true if @@our_loads[feature]
  # Assume backported features are Ruby libraries (i.e. not C)
  @loaded ||= $LOADED_FEATURES.group_by{|p| File.basename(p, ".rb")}
  if fullpaths = @loaded[File.basename(feature, ".rb")]
    fullpaths.any?{|fullpath|
      base_dir, = fullpath.partition("/#{feature}")
      $LOAD_PATH.include?(base_dir)
    }
  end
end