summaryrefslogtreecommitdiff
path: root/ext/pathname/pathname.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-23 14:16:06 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-23 14:16:06 +0000
commit526d246f715a1a0046942f942173c2d9447e78a5 (patch)
tree26a3ea7aed8c729dbf0d6425cc0d64683a5222ca /ext/pathname/pathname.c
parent645114b25c067f88c5d7e15e850f671272487b7d (diff)
* ext/pathname/pathname.c (path_each_line): Pathname#each_line
translated from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29077 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/pathname/pathname.c')
-rw-r--r--ext/pathname/pathname.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/ext/pathname/pathname.c b/ext/pathname/pathname.c
index 1d6b9ac..bd55da1 100644
--- a/ext/pathname/pathname.c
+++ b/ext/pathname/pathname.c
@@ -233,6 +233,35 @@ path_realdirpath(int argc, VALUE *argv, VALUE self)
}
/*
+ * call-seq:
+ * pathname.each_line {|line| ... }
+ * pathname.each_line(sep=$/ [, open_args]) {|line| block } -> nil
+ * pathname.each_line(limit [, open_args]) {|line| block } -> nil
+ * pathname.each_line(sep, limit [, open_args]) {|line| block } -> nil
+ * pathname.each_line(...) -> an_enumerator
+ *
+ * #each_line iterates over the line in the file. It yields a String object
+ * for each line.
+ *
+ * This method is availabel since 1.8.1.
+ */
+static VALUE
+path_each_line(int argc, VALUE *argv, VALUE self)
+{
+ VALUE args[4];
+ int n;
+
+ args[0] = get_strpath(self);
+ n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
+ if (rb_block_given_p()) {
+ return rb_block_call(rb_cIO, rb_intern("foreach"), 1+n, args, 0, 0);
+ }
+ else {
+ return rb_funcall2(rb_cIO, rb_intern("foreach"), 1+n, args);
+ }
+}
+
+/*
* See <tt>File.atime</tt>. Returns last access time.
*/
static VALUE
@@ -691,6 +720,7 @@ Init_pathname()
rb_define_method(rb_cPathname, "sub_ext", path_sub_ext, 1);
rb_define_method(rb_cPathname, "realpath", path_realpath, -1);
rb_define_method(rb_cPathname, "realdirpath", path_realdirpath, -1);
+ rb_define_method(rb_cPathname, "each_line", path_each_line, -1);
rb_define_method(rb_cPathname, "atime", path_atime, 0);
rb_define_method(rb_cPathname, "ctime", path_ctime, 0);
rb_define_method(rb_cPathname, "mtime", path_mtime, 0);