[前][次][番号順一覧][スレッド一覧]

ruby-changes:54210

From: akr <ko1@a...>
Date: Tue, 18 Dec 2018 12:10:02 +0900 (JST)
Subject: [ruby-changes:54210] akr:r66431 (trunk): Pathname#relative_path_from uses is_a?

akr	2018-12-18 12:09:54 +0900 (Tue, 18 Dec 2018)

  New Revision: 66431

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66431

  Log:
    Pathname#relative_path_from uses is_a?
    
    I reconsidered because simpler code would have better maintainablity.

  Modified files:
    trunk/ext/pathname/lib/pathname.rb
    trunk/test/pathname/test_pathname.rb
Index: ext/pathname/lib/pathname.rb
===================================================================
--- ext/pathname/lib/pathname.rb	(revision 66430)
+++ ext/pathname/lib/pathname.rb	(revision 66431)
@@ -503,13 +503,9 @@ class Pathname https://github.com/ruby/ruby/blob/trunk/ext/pathname/lib/pathname.rb#L503
   # 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)
Index: test/pathname/test_pathname.rb
===================================================================
--- test/pathname/test_pathname.rb	(revision 66430)
+++ test/pathname/test_pathname.rb	(revision 66431)
@@ -1439,6 +1439,7 @@ class TestPathname < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/pathname/test_pathname.rb#L1439
       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))

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]