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

ruby-changes:16914

From: akr <ko1@a...>
Date: Sun, 8 Aug 2010 07:34:32 +0900 (JST)
Subject: [ruby-changes:16914] Ruby:r28910 (trunk): * ext/pathname/pathname.c (path_fnmatch): Pathname#fnmatch and

akr	2010-08-08 07:33:51 +0900 (Sun, 08 Aug 2010)

  New Revision: 28910

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

  Log:
    * ext/pathname/pathname.c (path_fnmatch): Pathname#fnmatch and
      Pathname#fnmatch? 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 28909)
+++ ChangeLog	(revision 28910)
@@ -1,3 +1,8 @@
+Sun Aug  8 07:29:55 2010  Tanaka Akira  <akr@f...>
+
+	* ext/pathname/pathname.c (path_fnmatch): Pathname#fnmatch and
+	  Pathname#fnmatch? translated from pathname.rb.
+
 Sun Aug  8 07:18:22 2010  Tanaka Akira  <akr@f...>
 
 	* include/ruby/subst.h (snprintf): redefinition moved from ruby.h.
Index: ext/pathname/lib/pathname.rb
===================================================================
--- ext/pathname/lib/pathname.rb	(revision 28909)
+++ ext/pathname/lib/pathname.rb	(revision 28910)
@@ -512,13 +512,6 @@
 
 class Pathname    # * File *
 
-  # See <tt>File.fnmatch</tt>.  Return +true+ if the receiver matches the given
-  # pattern.
-  def fnmatch(pattern, *args) File.fnmatch(pattern, @path, *args) end
-
-  # See <tt>File.fnmatch?</tt> (same as #fnmatch).
-  def fnmatch?(pattern, *args) File.fnmatch?(pattern, @path, *args) end
-
   # See <tt>File.ftype</tt>.  Returns "type" of file ("file", "directory",
   # etc).
   def ftype() File.ftype(@path) end
Index: ext/pathname/pathname.c
===================================================================
--- ext/pathname/pathname.c	(revision 28909)
+++ ext/pathname/pathname.c	(revision 28910)
@@ -128,8 +128,8 @@
 
 /*
  *  call-seq:
- *    pathname.to_s             => string
- *    pathname.to_path          => string
+ *    pathname.to_s             -> string
+ *    pathname.to_path          -> string
  *
  *  Return the path as a String.
  *
@@ -296,6 +296,25 @@
 }
 
 /*
+ * call-seq:
+ *    pathname.fnmatch(pattern, [flags])        -> string
+ *    pathname.fnmatch?(pattern, [flags])       -> string
+ *   
+ * See <tt>File.fnmatch</tt>.  Return +true+ if the receiver matches the given
+ * pattern.
+ */
+static VALUE
+path_fnmatch(int argc, VALUE *argv, VALUE self)
+{
+    VALUE str = get_strpath(self);
+    VALUE pattern, flags;
+    if (rb_scan_args(argc, argv, "11", &pattern, &flags) == 1)
+        return rb_funcall(rb_cFile, rb_intern("fnmatch"), 2, pattern, str);
+    else
+        return rb_funcall(rb_cFile, rb_intern("fnmatch"), 3, pattern, str, flags);
+}
+
+/*
  * == Pathname
  *
  * Pathname represents a pathname which locates a file in a filesystem.
@@ -502,4 +521,6 @@
     rb_define_method(rb_cPathname, "lchmod", path_lchmod, 1);
     rb_define_method(rb_cPathname, "chown", path_chown, 2);
     rb_define_method(rb_cPathname, "lchown", path_lchown, 2);
+    rb_define_method(rb_cPathname, "fnmatch", path_fnmatch, -1);
+    rb_define_method(rb_cPathname, "fnmatch?", path_fnmatch, -1);
 }
Index: test/pathname/test_pathname.rb
===================================================================
--- test/pathname/test_pathname.rb	(revision 28909)
+++ test/pathname/test_pathname.rb	(revision 28910)
@@ -788,6 +788,8 @@
     path = Pathname("a")
     assert_equal(true, path.fnmatch("*"))
     assert_equal(false, path.fnmatch("*.*"))
+    assert_equal(false, Pathname(".foo").fnmatch("*"))
+    assert_equal(true, Pathname(".foo").fnmatch("*", File::FNM_DOTMATCH))
   end
 
   def test_fnmatch?

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

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