ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "sawa (Tsuyoshi Sawada)" <noreply@ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Subject: [ruby-core:111037] [Ruby master Misc#19155] documentation of Pathname#join with absolute path
Date: Mon, 28 Nov 2022 15:04:22 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-100290.20221128150422.52575@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-19155.20221128093530.52575@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#L248-L261

There was no description of this behavior in the documentation.




-- 
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/

      reply	other threads:[~2022-11-28 15:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-28  9:35 [ruby-core:111035] [Ruby master Misc#19155] documentation of Pathname#join with absolute path colorbox (box color)
2022-11-28 15:04 ` sawa (Tsuyoshi Sawada) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-100290.20221128150422.52575@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    --cc=ruby-core@ml.ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).