Skip to content

Commit

Permalink
fixed Pathname + method: if subclassing Pathname, when using + method…
Browse files Browse the repository at this point in the history
… on instance of that subclass, method returns instance of Pathname, not instance of subclass
  • Loading branch information
toy committed Dec 2, 2010
1 parent e33a500 commit 551d93a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ext/pathname/lib/pathname.rb
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
7 changes: 7 additions & 0 deletions test/pathname/test_pathname.rb
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

0 comments on commit 551d93a

Please sign in to comment.