summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-09-14 22:23:09 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-09-14 22:23:09 +0000
commitf84f1644138d20263f0939606dc8fc4f83fcc29f (patch)
treecdcf326da94a51633f3b6277c6d4cf9eeda9dd2d
parentd3a0629afc0fc0e1f59b1060ece81b973a9cdad8 (diff)
* ext/pathname/pathname.c (path_entries): Pathname#entries translated
from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29253 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--ext/pathname/lib/pathname.rb4
-rw-r--r--ext/pathname/pathname.c25
3 files changed, 30 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 933bc37d9b..baf6dbc7e6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Sep 15 07:22:20 2010 Tanaka Akira <akr@fsij.org>
+
+ * ext/pathname/pathname.c (path_entries): Pathname#entries translated
+ from pathname.rb.
+
Wed Sep 15 02:13:44 2010 Aaron Patterson <aaron@tenderlovemaking.com>
* ext/fiddle/closure.c : Don't use FFI closure alloc on OpenBSD.
diff --git a/ext/pathname/lib/pathname.rb b/ext/pathname/lib/pathname.rb
index 0efb5d4eb0..efe45afd6e 100644
--- a/ext/pathname/lib/pathname.rb
+++ b/ext/pathname/lib/pathname.rb
@@ -486,10 +486,6 @@ end
class Pathname # * Dir *
- # Return the entries (files and subdirectories) in the directory, each as a
- # Pathname object.
- def entries() Dir.entries(@path).map {|f| self.class.new(f) } end
-
# Iterates over the entries (files and subdirectories) in the directory. It
# yields a Pathname object for each entry.
#
diff --git a/ext/pathname/pathname.c b/ext/pathname/pathname.c
index 9370794a8c..cfeb94b1b7 100644
--- a/ext/pathname/pathname.c
+++ b/ext/pathname/pathname.c
@@ -858,6 +858,30 @@ path_s_getwd(VALUE klass)
}
/*
+ * Return the entries (files and subdirectories) in the directory, each as a
+ * Pathname object.
+ *
+ * The result may contain the current directory #<Pathname:.> and the parent
+ * directory #<Pathname:..>.
+ */
+static VALUE
+path_entries(VALUE self)
+{
+ VALUE klass, str, ary;
+ long i;
+ klass = rb_obj_class(self);
+ str = get_strpath(self);
+ ary = rb_funcall(rb_cDir, rb_intern("entries"), 1, str);
+ ary = rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
+ for (i = 0; i < RARRAY_LEN(ary); i++) {
+ VALUE elt = RARRAY_PTR(ary)[i];
+ elt = rb_class_new_instance(1, &elt, klass);
+ rb_ary_store(ary, i, elt);
+ }
+ return ary;
+}
+
+/*
* == Pathname
*
* Pathname represents a pathname which locates a file in a filesystem.
@@ -1113,4 +1137,5 @@ Init_pathname()
rb_define_singleton_method(rb_cPathname, "glob", path_s_glob, -1);
rb_define_singleton_method(rb_cPathname, "getwd", path_s_getwd, 0);
rb_define_singleton_method(rb_cPathname, "pwd", path_s_getwd, 0);
+ rb_define_method(rb_cPathname, "entries", path_entries, 0);
}