Skip to content

Commit e0452b4

Browse files
authored
Merge pull request #81 from BurdetteLamar/pn_plus_doc
[DOC] Doc for Pathname#+
2 parents 056d6ff + b4016cb commit e0452b4

1 file changed

Lines changed: 50 additions & 10 deletions

File tree

lib/pathname_builtin.rb

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -647,20 +647,60 @@ def ascend
647647
end
648648
end
649649

650+
# call-seq:
651+
# self + other -> new_pathname
650652
#
651-
# Appends a pathname fragment to +self+ to produce a new Pathname object.
652-
# Since +other+ is considered as a path relative to +self+, if +other+ is
653-
# an absolute path, the new Pathname object is created from just +other+.
653+
# Returns a new \Pathname object;
654+
# argument +other+ may be a string or another pathname.
654655
#
655-
# p1 = Pathname.new("/usr") # Pathname:/usr
656-
# p2 = p1 + "bin/ruby" # Pathname:/usr/bin/ruby
657-
# p3 = p1 + "/etc/passwd" # Pathname:/etc/passwd
656+
# When +other+ specifies a relative path (see #relative?),
657+
# it is combined with +self+ to form a new pathname:
658658
#
659-
# # / is aliased to +.
660-
# p4 = p1 / "bin/ruby" # Pathname:/usr/bin/ruby
661-
# p5 = p1 / "/etc/passwd" # Pathname:/etc/passwd
659+
# Pathname.new('/a/b') + 'c' # => #<Pathname:/a/b/c>
662660
#
663-
# This method doesn't access the file system; it is pure string manipulation.
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>
690+
#
691+
# When +other+ specifies an absolute path (see #absolute?),
692+
# equivalent to <tt>Pathname.new(other.to_s)</tt>:
693+
#
694+
# Pathname.new('/a') + '/b/c' # => #<Pathname:/b/c>
695+
#
696+
# Occurrences of <tt>'/'</tt>, <tt>'.'</tt>, and <tt>'..'</tt> are preserved:
697+
#
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
701+
# an existing (or even a valid) file or directory path:
702+
#
703+
# Pathname.new('/var') + 'nosuch:ever' # => #<Pathname:/var/nosuch:ever>
664704
#
665705
def +(other)
666706
other = Pathname.new(other) unless Pathname === other

0 commit comments

Comments
 (0)