[ruby-core:111035] [Ruby master Misc#19155] documentation of Pathname#join with absolute path

Issue #19155 has been reported by colorbox (box color). ---------------------------------------- Misc #19155: documentation of Pathname#join with absolute path https://bugs.ruby-lang.org/issues/19155 * Author: colorbox (box color) * Status: Open * Priority: Normal ---------------------------------------- Pathname#join ignores previous directory name before absolute path Is this intentional? ```irb irb(main):002:0> require 'pathname' => true irb(main):003:0> Pathname('/foo').join('bar', 'baz') => #<Pathname:/foo/bar/baz> irb(main):004:0> Pathname('/foo').join('bar', '/baz') => #<Pathname:/baz> irb(main):005:0> ➜✗ ruby -v ruby 3.0.4p208 (2022-04-12 revision 3fa771dded) [x86_64-darwin19] ``` I found that this behavior is intentional from test code but I cannot found reason. https://github.com/ruby/pathname/blob/master/test/pathname/test_pathname.rb#... There was no description of this behavior in the documentation. -- https://bugs.ruby-lang.org/

Issue #19155 has been updated by sawa (Tsuyoshi Sawada). There is a description. The doc https://docs.ruby-lang.org/ja/latest/class/Pathname.html#I_JOIN says: ```ruby path0 = Pathname("/usr") # Pathname:/usr path0 = path0.join("bin/ruby") # Pathname:/usr/bin/ruby # 上記の path0 の処理は下記の path1 と同様のパスになります path1 = Pathname("/usr") + "bin/ruby" # Pathname:/usr/bin/ruby path0 == path1 #=> true ``` where "上記の `path0` の処理は下記の `path1` と同様のパスになります" translates to English as "the path of `path0` above is handled on a par with `path1` below", which means that `join` follows the specification of `+`. And here https://docs.ruby-lang.org/ja/latest/class/Pathname.html#I_--2B it says:
self + other -> Pathname[permalink][rdoc][edit] self / other -> Pathname パス名を連結します。つまり、other を self からの相対パスとした新しい Pathname オブジェクトを生成して返します。 other が絶対パスなら単に other と同じ内容の Pathname オブジェクトが返されます。
where "`other` が絶対パスなら単に `other` と同じ内容の `Pathname` オブジェクトが返されます。" translates to English as "if `other` is an absolute path, then simply a `Pathname` object with the same content as `other` would be returned". ---------------------------------------- Misc #19155: documentation of Pathname#join with absolute path https://bugs.ruby-lang.org/issues/19155#change-100290 * Author: colorbox (box color) * Status: Open * Priority: Normal ---------------------------------------- Pathname#join ignores previous directory name before absolute path Is this intentional? ```irb irb(main):002:0> require 'pathname' => true irb(main):003:0> Pathname('/foo').join('bar', 'baz') => #<Pathname:/foo/bar/baz> irb(main):004:0> Pathname('/foo').join('bar', '/baz') => #<Pathname:/baz> irb(main):005:0> ➜✗ ruby -v ruby 3.0.4p208 (2022-04-12 revision 3fa771dded) [x86_64-darwin19] ``` I found that this behavior is intentional from test code but I cannot found reason. https://github.com/ruby/pathname/blob/master/test/pathname/test_pathname.rb#... There was no description of this behavior in the documentation. -- https://bugs.ruby-lang.org/
participants (2)
-
colorbox (box color)
-
sawa (Tsuyoshi Sawada)