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

ruby-changes:17017

From: akr <ko1@a...>
Date: Mon, 16 Aug 2010 21:40:26 +0900 (JST)
Subject: [ruby-changes:17017] Ruby:r29014 (trunk): * ext/pathname/pathname.c (path_basename): Pathname#basename translated

akr	2010-08-16 21:40:10 +0900 (Mon, 16 Aug 2010)

  New Revision: 29014

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

  Log:
    * ext/pathname/pathname.c (path_basename): Pathname#basename translated
      from pathname.rb.

  Modified files:
    trunk/ChangeLog
    trunk/ext/pathname/lib/pathname.rb
    trunk/ext/pathname/pathname.c
    trunk/test/pathname/test_pathname.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 29013)
+++ ChangeLog	(revision 29014)
@@ -1,3 +1,8 @@
+Mon Aug 16 21:39:33 2010  Tanaka Akira  <akr@f...>
+
+	* ext/pathname/pathname.c (path_basename): Pathname#basename translated
+	  from pathname.rb.
+
 Mon Aug 16 20:26:13 2010  Narihiro Nakamura  <narihiro@n...>
 
 	* gc.c (gc_profile_result): Index begins with 1.
Index: ext/pathname/lib/pathname.rb
===================================================================
--- ext/pathname/lib/pathname.rb	(revision 29013)
+++ ext/pathname/lib/pathname.rb	(revision 29014)
@@ -512,9 +512,6 @@
 
 class Pathname    # * File *
 
-  # See <tt>File.basename</tt>.  Returns the last component of the path.
-  def basename(*args) self.class.new(File.basename(@path, *args)) end
-
   # See <tt>File.dirname</tt>.  Returns all but the last component of the path.
   def dirname() self.class.new(File.dirname(@path)) end
 
Index: ext/pathname/pathname.c
===================================================================
--- ext/pathname/pathname.c	(revision 29013)
+++ ext/pathname/pathname.c	(revision 29014)
@@ -424,6 +424,22 @@
 }
 
 /*
+ * See <tt>File.basename</tt>.  Returns the last component of the path.
+ */
+static VALUE
+path_basename(int argc, VALUE *argv, VALUE self)
+{
+    VALUE str = get_strpath(self);
+    VALUE fext;
+    int n;
+    if (rb_scan_args(argc, argv, "01", &fext) == 0)
+        str = rb_funcall(rb_cFile, rb_intern("basename"), 1, str);
+    else
+        str = rb_funcall(rb_cFile, rb_intern("basename"), 2, str, fext);
+    return rb_class_new_instance(1, &str, rb_obj_class(self));
+}
+
+/*
  * == Pathname
  *
  * Pathname represents a pathname which locates a file in a filesystem.
@@ -642,4 +658,5 @@
     rb_define_method(rb_cPathname, "make_symlink", path_make_symlink, 1);
     rb_define_method(rb_cPathname, "truncate", path_truncate, 1);
     rb_define_method(rb_cPathname, "utime", path_utime, 2);
+    rb_define_method(rb_cPathname, "basename", path_basename, -1);
 }
Index: test/pathname/test_pathname.rb
===================================================================
--- test/pathname/test_pathname.rb	(revision 29013)
+++ test/pathname/test_pathname.rb	(revision 29014)
@@ -915,6 +915,7 @@
 
   def test_basename
     assert_equal(Pathname("basename"), Pathname("dirname/basename").basename)
+    assert_equal(Pathname("bar"), Pathname("foo/bar.x").basename(".x"))
   end
 
   def test_dirname

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

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