From: "jeremyevans0 (Jeremy Evans) via ruby-core" Date: 2023-11-03T05:44:01+00:00 Subject: [ruby-core:115234] [Ruby master Feature#19985] Support `Pathname` for `require` Issue #19985 has been updated by jeremyevans0 (Jeremy Evans). martinemde (Martin Emde) wrote in #note-5: > It is funny to me that you would say it���s not a path just because not all paths are valid. What else could it possibly be? What the argument to `require` actually is is a feature name. That's why the argument to the method in the call-seq is `name` (not `filename` or `path`), and the first line of the `require` documentation mentions that it returns `true` or `false` depending on whether "the *feature* is already loaded". > Ruby docs for require: > > > If the filename neither resolves to an absolute path nor starts with ���./��� or ���../���, the file will be searched for in the library directories listed in $LOAD_PATH ($:). If the filename starts with ���./��� or ���../���, resolution is based on Dir.pwd. > > https://ruby-doc.org/3.2.2/Kernel.html#method-i-require Certainly the documentation for the `require` could be improved, because it implies that a filename that resolves to a path will be used, which is not generally the case as I showed previously. It's only the case for absolute paths or paths starting with `./` or `../`, and only if the path ends with a recognized file extension. In Ruby code, all valid `load` calls use paths. 99.9%+ of valid `require` calls do not use paths. I would guess that the majority of times that an argument starting with `/`, `./`, or `../` is passed to `require`, it probably still leaves off the file extension. > Walks like a duck, quacks like a duck, looks like a duck, referred to as a duck, lays duck eggs, but certain duck species not allowed => not duck. It's a platypus, you shouldn't call it a duck just because it has a bill. :) ---------------------------------------- Feature #19985: Support `Pathname` for `require` https://bugs.ruby-lang.org/issues/19985#change-105150 * Author: vo.x (Vit Ondruch) * Status: Open * Priority: Normal ---------------------------------------- It seems that RubyGems / Bundler `require` method overrides of accept `Pathname` as and argument ~~~ $ ruby -rpathname -e ' pa = Pathname.new("test") require pa ' :85:in `require': cannot load such file -- test (LoadError) from :85:in `require' from -e:3:in `
' ~~~ while plain Ruby require does not: ~~~ $ ruby --disable-gems -rpathname -e ' pa = Pathname.new("test") require pa ' -e:3:in `require': no implicit conversion of Pathname into String (TypeError) from -e:3:in `
' ~~~ This inconsistency is surprising. It seems that RubyGems / Bundler developers think [1] that Ruby `require` should also accept `Pathname`. ~~~ $ ruby -v ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux] ~~~ [1]: https://github.com/rubygems/rubygems/pull/7128 -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/