Skip to content

Commit

Permalink
Pathname#relative_path_from uses is_a?
Browse files Browse the repository at this point in the history
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
  • Loading branch information
akr committed Dec 18, 2018
1 parent 623c6d9 commit 78dc3da
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
8 changes: 2 additions & 6 deletions ext/pathname/lib/pathname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -503,13 +503,9 @@ def each_child(with_directory=true, &b)
# ArgumentError is raised when it cannot find a relative path.
#
def relative_path_from(base_directory)
base_directory = Pathname.new(base_directory) unless base_directory.is_a? Pathname
dest_directory = self.cleanpath.to_s
base_directory =
if base_directory.respond_to? :cleanpath
base_directory
else
Pathname.new(base_directory)
end.cleanpath.to_s
base_directory = base_directory.cleanpath.to_s
dest_prefix = dest_directory
dest_names = []
while r = chop_basename(dest_prefix)
Expand Down
1 change: 1 addition & 0 deletions test/pathname/test_pathname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,7 @@ def test_relative_path_from_mock
Pathname.new("/foo/bar").relative_path_from("/foo/baz"))
obj = Object.new
def obj.cleanpath() Pathname.new("/foo/baz") end
def obj.is_a?(m) m == Pathname end
assert_equal(
Pathname.new("../bar"),
Pathname.new("/foo/bar").relative_path_from(obj))
Expand Down

0 comments on commit 78dc3da

Please sign in to comment.