From f84f1644138d20263f0939606dc8fc4f83fcc29f Mon Sep 17 00:00:00 2001 From: akr Date: Tue, 14 Sep 2010 22:23:09 +0000 Subject: * 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 --- ext/pathname/pathname.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'ext/pathname/pathname.c') 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 @@ -857,6 +857,30 @@ path_s_getwd(VALUE klass) return rb_class_new_instance(1, &str, klass); } +/* + * Return the entries (files and subdirectories) in the directory, each as a + * Pathname object. + * + * The result may contain the current directory # and the parent + * directory #. + */ +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 * @@ -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); } -- cgit v1.2.3