mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
lib/pathname.rb (Pathname#+): if self or the argument is `.', return another.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4918 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
dc592364e6
commit
fb55a6d12f
2 changed files with 13 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
Fri Nov 7 11:06:57 2003 Tanaka Akira <akr@m17n.org>
|
Fri Nov 7 12:50:28 2003 Tanaka Akira <akr@m17n.org>
|
||||||
|
|
||||||
* lib/pathname.rb (Pathname#+): return the argument if self is `.'.
|
* lib/pathname.rb (Pathname#+): if self or the argument is `.', return
|
||||||
|
another.
|
||||||
|
|
||||||
Fri Nov 7 10:23:24 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Fri Nov 7 10:23:24 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
|
|
@ -216,10 +216,13 @@ class Pathname
|
||||||
# If self is the current working directory `.' or
|
# If self is the current working directory `.' or
|
||||||
# the argument is absolute pathname,
|
# the argument is absolute pathname,
|
||||||
# the argument is just returned.
|
# the argument is just returned.
|
||||||
|
# If the argument is `.', self is returned.
|
||||||
def +(other)
|
def +(other)
|
||||||
other = Pathname.new(other) unless Pathname === other
|
other = Pathname.new(other) unless Pathname === other
|
||||||
if @path == '.' || other.absolute?
|
if @path == '.' || other.absolute?
|
||||||
other
|
other
|
||||||
|
elsif other.to_s == '.'
|
||||||
|
self
|
||||||
elsif %r{/\z} =~ @path
|
elsif %r{/\z} =~ @path
|
||||||
Pathname.new(@path + other.to_s)
|
Pathname.new(@path + other.to_s)
|
||||||
else
|
else
|
||||||
|
@ -685,5 +688,12 @@ if $0 == __FILE__
|
||||||
assert_relpath_err(".", "..")
|
assert_relpath_err(".", "..")
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue