зеркало из https://github.com/github/ruby.git
Pathname: Have #relative_path_from accept String argument.
[Fix GH-1975] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65706 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
5ad8e42bef
Коммит
dde0e30c2d
|
@ -503,6 +503,7 @@ class Pathname
|
||||||
# ArgumentError is raised when it cannot find a relative path.
|
# ArgumentError is raised when it cannot find a relative path.
|
||||||
#
|
#
|
||||||
def relative_path_from(base_directory)
|
def relative_path_from(base_directory)
|
||||||
|
base_directory = Pathname.new(base_directory) unless Pathname === base_directory
|
||||||
dest_directory = self.cleanpath.to_s
|
dest_directory = self.cleanpath.to_s
|
||||||
base_directory = base_directory.cleanpath.to_s
|
base_directory = base_directory.cleanpath.to_s
|
||||||
dest_prefix = dest_directory
|
dest_prefix = dest_directory
|
||||||
|
|
|
@ -291,9 +291,10 @@ class TestPathname < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def relative_path_from(dest_directory, base_directory)
|
def relative_path_from(dest_directory, base_directory)
|
||||||
Pathname.new(dest_directory).relative_path_from(Pathname.new(base_directory)).to_s
|
Pathname.new(dest_directory).relative_path_from(base_directory).to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defassert(:relative_path_from, "../a", Pathname.new("a"), "b")
|
||||||
defassert(:relative_path_from, "../a", "a", "b")
|
defassert(:relative_path_from, "../a", "a", "b")
|
||||||
defassert(:relative_path_from, "../a", "a", "b/")
|
defassert(:relative_path_from, "../a", "a", "b/")
|
||||||
defassert(:relative_path_from, "../a", "a/", "b")
|
defassert(:relative_path_from, "../a", "a/", "b")
|
||||||
|
|
Загрузка…
Ссылка в новой задаче