summaryrefslogtreecommitdiffstats
path: root/lib/pathname.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-11-07 03:51:15 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-11-07 03:51:15 +0000
commita55682a2dbf68c851dec212e0d788f75635252a4 (patch)
tree7574f78c66e95a40fcc505c0185d1448f62d67ea /lib/pathname.rb
parent83927c56aa3d8de1a631616d0e30cfec24315998 (diff)
downloadruby-a55682a2dbf68c851dec212e0d788f75635252a4.tar.gz
ruby-a55682a2dbf68c851dec212e0d788f75635252a4.tar.xz
ruby-a55682a2dbf68c851dec212e0d788f75635252a4.zip
lib/pathname.rb (Pathname#+): if self or the argument is `.', return another.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@4918 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/pathname.rb')
-rw-r--r--lib/pathname.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/pathname.rb b/lib/pathname.rb
index c433f5dff..96aa57330 100644
--- a/lib/pathname.rb
+++ b/lib/pathname.rb
@@ -216,10 +216,13 @@ class Pathname
# If self is the current working directory `.' or
# the argument is absolute pathname,
# the argument is just returned.
+ # If the argument is `.', self is returned.
def +(other)
other = Pathname.new(other) unless Pathname === other
if @path == '.' || other.absolute?
other
+ elsif other.to_s == '.'
+ self
elsif %r{/\z} =~ @path
Pathname.new(@path + other.to_s)
else
@@ -685,5 +688,12 @@ if $0 == __FILE__
assert_relpath_err(".", "..")
end
+ def test_plus
+ assert_equal(Pathname.new('a/b'), Pathname.new('a') + Pathname.new('b'))
+ assert_equal(Pathname.new('a'), Pathname.new('a') + Pathname.new('.'))
+ assert_equal(Pathname.new('b'), Pathname.new('.') + Pathname.new('b'))
+ assert_equal(Pathname.new('.'), Pathname.new('.') + Pathname.new('.'))
+ assert_equal(Pathname.new('/b'), Pathname.new('a') + Pathname.new('/b'))
+ end
end
end