[macruby-changes] [1385] MacRuby/branches/experimental/io.c
source_changes at macosforge.org
source_changes at macosforge.org
Mon Apr 6 10:34:03 PDT 2009
Revision: 1385
http://trac.macosforge.org/projects/ruby/changeset/1385
Author: pthomson at apple.com
Date: 2009-04-06 10:34:01 -0700 (Mon, 06 Apr 2009)
Log Message:
-----------
Implemented IO#readlines, IO#each_byte and IO#each_char.
Modified Paths:
--------------
MacRuby/branches/experimental/io.c
Modified: MacRuby/branches/experimental/io.c
===================================================================
--- MacRuby/branches/experimental/io.c 2009-04-06 12:16:19 UTC (rev 1384)
+++ MacRuby/branches/experimental/io.c 2009-04-06 17:34:01 UTC (rev 1385)
@@ -1310,7 +1310,13 @@
static VALUE
rb_io_readlines(VALUE io, SEL sel, int argc, VALUE *argv)
{
-rb_notimplement();
+ VALUE array = rb_ary_new();
+ VALUE line = rb_io_gets_m(io, sel, argc, argv);
+ while (!NIL_P(line)) {
+ rb_ary_push(array, line);
+ line = rb_io_gets_m(io, sel, argc, argv);
+ }
+ return array;
}
/*
@@ -1340,7 +1346,12 @@
static VALUE
rb_io_each_line(VALUE io, SEL sel, int argc, VALUE *argv)
{
-rb_notimplement();
+ VALUE line = rb_io_gets_m(io, sel, argc, argv);
+ while (!NIL_P(line)) {
+ rb_vm_yield(1, &line);
+ line = rb_io_gets_m(io, sel, argc, argv);
+ }
+ return io;
}
/*
@@ -1381,10 +1392,18 @@
* f.each_char {|c| print c, ' ' } #=> #<File:testfile>
*/
+static VALUE rb_io_getc(VALUE io, SEL sel);
+
static VALUE
rb_io_each_char(VALUE io, SEL sel)
{
-rb_notimplement();
+ VALUE c = rb_io_getc(io, 0);
+
+ while (!NIL_P(c)) {
+ rb_vm_yield(1, &c);
+ c = rb_io_getc(io, 0);
+ }
+ return io;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090406/81461ac8/attachment.html>
More information about the macruby-changes
mailing list