From: "zverok (Victor Shepelev) via ruby-core" <ruby-core@...>
Date: 2023-11-02T10:54:00+00:00
Subject: [ruby-core:115228] [Ruby master Feature#19985] Support `Pathname` for `require`

Issue #19985 has been updated by zverok (Victor Shepelev).


Actually, it seems kinda weird that Pathname doesn't have implicit conversion to a String (`#to_str`).
OTOH, [Pathname#to_path](https://docs.ruby-lang.org/en/3.2/Pathname.html#method-i-to_path) docs seem to claim that having `#to_path` is an agreement to represent "path-like" things, which, say `File.open` respects, but bare `require` ignores.

Rubygems [respect the agreement](https://github.com/rubygems/rubygems/blob/master/lib/rubygems/core_ext/kernel_require.rb#L40) through calling [File.path](https://docs.ruby-lang.org/en/3.2/File.html#method-c-path). The funny thing though is there is no method where the agreement is documented! Even `File.path` which implements it never documents how exactly it evaluates "string representation of the path" :)

----------------------------------------
Feature #19985: Support `Pathname` for `require`
https://bugs.ruby-lang.org/issues/19985#change-105144

* 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
'
<internal:/usr/share/rubygems/rubygems/core_ext/kernel_require.rb>:85:in `require': cannot load such file -- test (LoadError)
	from <internal:/usr/share/rubygems/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from -e:3:in `<main>'
~~~

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 `<main>'
~~~

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/