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

ruby-changes:53490

From: marcandre <ko1@a...>
Date: Tue, 13 Nov 2018 15:20:10 +0900 (JST)
Subject: [ruby-changes:53490] marcandRe: r65706 (trunk): Pathname: Have #relative_path_from accept String argument.

marcandre	2018-11-13 15:20:06 +0900 (Tue, 13 Nov 2018)

  New Revision: 65706

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

  Log:
    Pathname: Have #relative_path_from accept String argument.
    
    [Fix GH-1975]

  Modified files:
    trunk/ext/pathname/lib/pathname.rb
    trunk/test/pathname/test_pathname.rb
Index: test/pathname/test_pathname.rb
===================================================================
--- test/pathname/test_pathname.rb	(revision 65705)
+++ test/pathname/test_pathname.rb	(revision 65706)
@@ -291,9 +291,10 @@ class TestPathname < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/pathname/test_pathname.rb#L291
   end
 
   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
 
+  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")
Index: ext/pathname/lib/pathname.rb
===================================================================
--- ext/pathname/lib/pathname.rb	(revision 65705)
+++ ext/pathname/lib/pathname.rb	(revision 65706)
@@ -503,6 +503,7 @@ 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 Pathname === base_directory
     dest_directory = self.cleanpath.to_s
     base_directory = base_directory.cleanpath.to_s
     dest_prefix = dest_directory

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

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