diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/pathname/lib/pathname.rb | 7 | ||||
-rw-r--r-- | ext/pathname/pathname.c | 25 |
2 files changed, 23 insertions, 9 deletions
diff --git a/ext/pathname/lib/pathname.rb b/ext/pathname/lib/pathname.rb index b3bc42d9a1..d2373ebdb1 100644 --- a/ext/pathname/lib/pathname.rb +++ b/ext/pathname/lib/pathname.rb @@ -512,13 +512,6 @@ end 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 diff --git a/ext/pathname/pathname.c b/ext/pathname/pathname.c index e317e85618..81b6d23e6d 100644 --- a/ext/pathname/pathname.c +++ b/ext/pathname/pathname.c @@ -128,8 +128,8 @@ path_hash(VALUE self) /* * 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 @@ path_lchown(VALUE self, VALUE owner, VALUE group) } /* + * 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 @@ Init_pathname() 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); } |