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

ruby-changes:33328

From: kazu <ko1@a...>
Date: Tue, 25 Mar 2014 23:42:44 +0900 (JST)
Subject: [ruby-changes:33328] kazu:r45407 (trunk): remove unnecessary unshift

kazu	2014-03-25 23:42:36 +0900 (Tue, 25 Mar 2014)

  New Revision: 45407

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45407

  Log:
    remove unnecessary unshift
    
    * ext/pathname/lib/pathname.rb (Pathname#join): remove unnecessary unshift.
    * test/pathname/test_pathname.rb (TestPathname#test_join): add tests.

  Modified files:
    trunk/ChangeLog
    trunk/ext/pathname/lib/pathname.rb
    trunk/test/pathname/test_pathname.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45406)
+++ ChangeLog	(revision 45407)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Mar 25 23:32:25 2014  Kazuhiro NISHIYAMA  <zn@m...>
+
+	* ext/pathname/lib/pathname.rb (Pathname#join): remove unnecessary
+	  unshift.
+
+	* test/pathname/test_pathname.rb (TestPathname#test_join): add tests.
+
 Tue Mar 25 16:47:36 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* parse.y (lex_state_e, parser_params, f_arglist, parser_yylex):
Index: ext/pathname/lib/pathname.rb
===================================================================
--- ext/pathname/lib/pathname.rb	(revision 45406)
+++ ext/pathname/lib/pathname.rb	(revision 45407)
@@ -384,7 +384,6 @@ class Pathname https://github.com/ruby/ruby/blob/trunk/ext/pathname/lib/pathname.rb#L384
   #       #=> true
   #
   def join(*args)
-    args.unshift self
     result = args.pop
     result = Pathname.new(result) unless Pathname === result
     return result if result.absolute?
@@ -393,7 +392,7 @@ class Pathname https://github.com/ruby/ruby/blob/trunk/ext/pathname/lib/pathname.rb#L392
       result = arg + result
       return result if result.absolute?
     }
-    result
+    self + result
   end
 
   #
Index: test/pathname/test_pathname.rb
===================================================================
--- test/pathname/test_pathname.rb	(revision 45406)
+++ test/pathname/test_pathname.rb	(revision 45407)
@@ -234,6 +234,14 @@ class TestPathname < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/pathname/test_pathname.rb#L234
   def test_join
     r = Pathname("a").join(Pathname("b"), Pathname("c"))
     assert_equal(Pathname("a/b/c"), r)
+    r = Pathname("/a").join(Pathname("b"), Pathname("c"))
+    assert_equal(Pathname("/a/b/c"), r)
+    r = Pathname("/a").join(Pathname("/b"), Pathname("c"))
+    assert_equal(Pathname("/b/c"), r)
+    r = Pathname("/a").join(Pathname("/b"), Pathname("/c"))
+    assert_equal(Pathname("/c"), r)
+    r = Pathname("/a").join("/b", "/c")
+    assert_equal(Pathname("/c"), r)
   end
 
   def test_absolute

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

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