diff --git a/lib/pathname_builtin.rb b/lib/pathname_builtin.rb index 878603d..d649a0d 100644 --- a/lib/pathname_builtin.rb +++ b/lib/pathname_builtin.rb @@ -647,20 +647,60 @@ def ascend end end + # call-seq: + # self + other -> new_pathname # - # Appends a pathname fragment to +self+ to produce a new Pathname object. - # Since +other+ is considered as a path relative to +self+, if +other+ is - # an absolute path, the new Pathname object is created from just +other+. + # Returns a new \Pathname object; + # argument +other+ may be a string or another pathname. # - # p1 = Pathname.new("/usr") # Pathname:/usr - # p2 = p1 + "bin/ruby" # Pathname:/usr/bin/ruby - # p3 = p1 + "/etc/passwd" # Pathname:/etc/passwd + # When +other+ specifies a relative path (see #relative?), + # it is combined with +self+ to form a new pathname: # - # # / is aliased to +. - # p4 = p1 / "bin/ruby" # Pathname:/usr/bin/ruby - # p5 = p1 / "/etc/passwd" # Pathname:/etc/passwd + # Pathname.new('/a/b') + 'c' # => # # - # This method doesn't access the file system; it is pure string manipulation. + # Extra component separators ('/') are removed: + # + # Pathname.new('/a/b/') + 'c' # => # + # + # Extra current-directory components ('.') are removed: + # + # Pathname.new('a') + '.' # => # + # Pathname.new('.') + 'a' # => # + # Pathname.new('.') + '.' # => # + # + # Parent-directory components ('..') are: + # + # - Resolved, when possible: + # + # Pathname.new('a') + '..' # => # + # Pathname.new('a/b') + '..' # => # + # Pathname.new('/') + '../a' # => # + # Pathname.new('a') + '../b' # => # + # Pathname.new('a/b') + '../c' # => # + # Pathname.new('a//b/c') + '../d//e' # => # + # + # - Removed, when not needed: + # + # Pathname.new('/') + '..' # => # + # + # - Retained, when needed: + # + # Pathname.new('..') + '..' # => # + # Pathname.new('..') + '../a' # => # + # + # When +other+ specifies an absolute path (see #absolute?), + # equivalent to Pathname.new(other.to_s): + # + # Pathname.new('/a') + '/b/c' # => # + # + # Occurrences of '/', '.', and '..' are preserved: + # + # Pathname.new('/a') + '//b//c/./../d' # => # + # + # This method does not access the file system, so +other+ need not represent + # an existing (or even a valid) file or directory path: + # + # Pathname.new('/var') + 'nosuch:ever' # => # # def +(other) other = Pathname.new(other) unless Pathname === other