ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:111035] [Ruby master Misc#19155] documentation of Pathname#join with absolute path
@ 2022-11-28  9:35 colorbox (box color)
  2022-11-28 15:04 ` [ruby-core:111037] " sawa (Tsuyoshi Sawada)
  0 siblings, 1 reply; 2+ messages in thread
From: colorbox (box color) @ 2022-11-28  9:35 UTC (permalink / raw)
  To: ruby-core

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [ruby-core:111037] [Ruby master Misc#19155] documentation of Pathname#join with absolute path
  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)
  0 siblings, 0 replies; 2+ messages in thread
From: sawa (Tsuyoshi Sawada) @ 2022-11-28 15:04 UTC (permalink / raw)
  To: ruby-core

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/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-28 15:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [ruby-core:111037] " sawa (Tsuyoshi Sawada)

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).