Skip to content

Commit b4016cb

Browse files
committed
Add details
1 parent c6d3287 commit b4016cb

1 file changed

Lines changed: 39 additions & 8 deletions

File tree

lib/pathname_builtin.rb

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -654,22 +654,53 @@ def ascend
654654
# argument +other+ may be a string or another pathname.
655655
#
656656
# When +other+ specifies a relative path (see #relative?),
657-
# equivalent to <tt>Pathname.new(self.to_s + other.to_s)</tt>:
657+
# it is combined with +self+ to form a new pathname:
658658
#
659-
# pn = Pathname.new("/usr") # => #<Pathname:/usr>
660-
# pn + 'bin/ruby' # => #<Pathname:/usr/bin/ruby>
661-
# pn + Pathname.new('bin/ruby') # => #<Pathname:/usr/bin/ruby>
659+
# Pathname.new('/a/b') + 'c' # => #<Pathname:/a/b/c>
660+
#
661+
# Extra component separators (<tt>'/'</tt>) are removed:
662+
#
663+
# Pathname.new('/a/b/') + 'c' # => #<Pathname:/a/b/c>
664+
#
665+
# Extra current-directory components (<tt>'.'</tt>) are removed:
666+
#
667+
# Pathname.new('a') + '.' # => #<Pathname:a>
668+
# Pathname.new('.') + 'a' # => #<Pathname:a>
669+
# Pathname.new('.') + '.' # => #<Pathname:.>
670+
#
671+
# Parent-directory components (<tt>'..'</tt>) are:
672+
#
673+
# - Resolved, when possible:
674+
#
675+
# Pathname.new('a') + '..' # => #<Pathname:.>
676+
# Pathname.new('a/b') + '..' # => #<Pathname:a>
677+
# Pathname.new('/') + '../a' # => #<Pathname:/a>
678+
# Pathname.new('a') + '../b' # => #<Pathname:b>
679+
# Pathname.new('a/b') + '../c' # => #<Pathname:a/c>
680+
# Pathname.new('a//b/c') + '../d//e' # => #<Pathname:a//b/d//e>
681+
#
682+
# - Removed, when not needed:
683+
#
684+
# Pathname.new('/') + '..' # => #<Pathname:/>
685+
#
686+
# - Retained, when needed:
687+
#
688+
# Pathname.new('..') + '..' # => #<Pathname:../..>
689+
# Pathname.new('..') + '../a' # => #<Pathname:../../a>
662690
#
663691
# When +other+ specifies an absolute path (see #absolute?),
664692
# equivalent to <tt>Pathname.new(other.to_s)</tt>:
665693
#
666-
# pn + Pathname.new('/etc/password') # => #<Pathname:/etc/password>
667-
# pn + '/etc/password' # => #<Pathname:/etc/password>
694+
# Pathname.new('/a') + '/b/c' # => #<Pathname:/b/c>
695+
#
696+
# Occurrences of <tt>'/'</tt>, <tt>'.'</tt>, and <tt>'..'</tt> are preserved:
668697
#
669-
# Does not access the file system, so +other+ need not represent
698+
# Pathname.new('/a') + '//b//c/./../d' # => #<Pathname://b//c/./../d>
699+
#
700+
# This method does not access the file system, so +other+ need not represent
670701
# an existing (or even a valid) file or directory path:
671702
#
672-
# pn + 'nosuch:ever' # => #<Pathname:/usr/nosuch:ever>
703+
# Pathname.new('/var') + 'nosuch:ever' # => #<Pathname:/var/nosuch:ever>
673704
#
674705
def +(other)
675706
other = Pathname.new(other) unless Pathname === other

0 commit comments

Comments
 (0)