mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Pathname#relative_path_from uses is_a?
I reconsidered because simpler code would have better maintainablity. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
623c6d972a
commit
78dc3da299
2 changed files with 3 additions and 6 deletions
|
@ -503,13 +503,9 @@ 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 base_directory.is_a? Pathname
|
||||||
dest_directory = self.cleanpath.to_s
|
dest_directory = self.cleanpath.to_s
|
||||||
base_directory =
|
base_directory = base_directory.cleanpath.to_s
|
||||||
if base_directory.respond_to? :cleanpath
|
|
||||||
base_directory
|
|
||||||
else
|
|
||||||
Pathname.new(base_directory)
|
|
||||||
end.cleanpath.to_s
|
|
||||||
dest_prefix = dest_directory
|
dest_prefix = dest_directory
|
||||||
dest_names = []
|
dest_names = []
|
||||||
while r = chop_basename(dest_prefix)
|
while r = chop_basename(dest_prefix)
|
||||||
|
|
|
@ -1439,6 +1439,7 @@ class TestPathname < Test::Unit::TestCase
|
||||||
Pathname.new("/foo/bar").relative_path_from("/foo/baz"))
|
Pathname.new("/foo/bar").relative_path_from("/foo/baz"))
|
||||||
obj = Object.new
|
obj = Object.new
|
||||||
def obj.cleanpath() Pathname.new("/foo/baz") end
|
def obj.cleanpath() Pathname.new("/foo/baz") end
|
||||||
|
def obj.is_a?(m) m == Pathname end
|
||||||
assert_equal(
|
assert_equal(
|
||||||
Pathname.new("../bar"),
|
Pathname.new("../bar"),
|
||||||
Pathname.new("/foo/bar").relative_path_from(obj))
|
Pathname.new("/foo/bar").relative_path_from(obj))
|
||||||
|
|
Loading…
Add table
Reference in a new issue