Issue #6376 has been updated by mame (Yusuke Endoh).

Assignee changed from mame (Yusuke Endoh) to matz (Yukihiro Matsumoto)

Yes I know what you want.  But I don't know why you want it.  In general, I don't think that it is a good idea to depend on whether a feature is loaded or not.  Rather, you should make sure to require what feature you need.

So, please elaborate your use case.  I guessed one use case: you want to use one of many alternative libraries, for example, either eventmachine or Celluloid::IO.  In such a case, you may want to try to require one, and if a LoadError is raised, then require the other.

-- 
Yusuke Endoh <mame / tsg.ne.jp>
----------------------------------------
Feature #6376: Feature lookup and checking if feature is loaded
https://bugs.ruby-lang.org/issues/6376#change-33206

Author: trans (Thomas Sawyer)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor


$LOADED_FEATURES is useful to know what "files" have been loaded. But it doesn't really tell us what "features" have been loaded. If there where were a way to look-up a load path, without actually loading it then it would be possible to compare that to $LOADED_FEATURES and thus know. e.g.

    require 'ostruct'
    $LOADED_FEATURES #=> [..., "/home/trans/.local/lib/ry/rubies/1.9.3-p125/lib/ruby/1.9.1/ostruct.rb"]

    path = require_path('ostruct') #=> "/home/trans/.local/lib/ry/rubies/1.9.3-p125/lib/ruby/1.9.1/ostruct.rb"
    $LOADED_FEATURES.include?(path)

Of course, it would be nice to also have:

    required?('ostruct')  #=> true

These methods could be class methods of special module, if it's important to keep the Kernel more tidy, e.g. `Ruby.required?('ostruct')`.

I am currently working on a project where I need this (and have a couple of other projects that could use it too) and I've had to implement the whole thing from scratch, which isn't simple, nor fast, nor am I 100% confident that it specs exactly to Ruby's own lookup procedure. So it would be much better if Ruby would expose its lookup functionality.




-- 
http://bugs.ruby-lang.org/