Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ext/pathname/lib/pathname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ def ascend
# This method doesn't access the file system; it is pure string manipulation.
#
def +(other)
other = Pathname.new(other) unless Pathname === other
Pathname.new(plus(@path, other.to_s))
other = self.class.new(other) unless Pathname === other
self.class.new(plus(@path, other.to_s))
end

def plus(path1, path2) # -> path
Expand Down Expand Up @@ -476,9 +476,9 @@ def relative_path_from(base_directory)
base_names.fill('..')
relpath_names = base_names + dest_names
if relpath_names.empty?
Pathname.new('.')
self.class.new('.')
else
Pathname.new(File.join(*relpath_names))
self.class.new(File.join(*relpath_names))
end
end
end
Expand Down
11 changes: 11 additions & 0 deletions test/pathname/test_pathname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def self.defassert(name, result, *args)
DOSISH_DRIVE_LETTER = File.dirname("A:") == "A:."
DOSISH_UNC = File.dirname("//") == "//"

class SuperPathname < Pathname
end

def cleanpath_aggressive(path)
Pathname.new(path).cleanpath.to_s
end
Expand Down Expand Up @@ -204,6 +207,10 @@ def plus(path1, path2) # -> path

defassert(:plus, 'a//b/d//e', 'a//b/c', '../d//e')

define_assertion(:plus) {
assert_instance_of(SuperPathname, SuperPathname.new('a') + 'b')
}

def test_parent
assert_equal(Pathname("."), Pathname("a").parent)
end
Expand Down Expand Up @@ -306,6 +313,10 @@ def self.defassert_raise(name, exc, *args)
defassert_raise(:relative_path_from, ArgumentError, "a", "..")
defassert_raise(:relative_path_from, ArgumentError, ".", "..")

define_assertion(:relative_path_from) {
assert_instance_of(SuperPathname, SuperPathname.new('a').relative_path_from(SuperPathname.new('b')))
}

def with_tmpchdir(base=nil)
Dir.mktmpdir(base) {|d|
d = Pathname.new(d).realpath.to_s
Expand Down