[macruby-changes] [4909] MacRuby/trunk/io.c
source_changes at macosforge.org
source_changes at macosforge.org
Mon Nov 15 19:06:05 PST 2010
Revision: 4909
http://trac.macosforge.org/projects/ruby/changeset/4909
Author: watson1978 at gmail.com
Date: 2010-11-15 19:06:03 -0800 (Mon, 15 Nov 2010)
Log Message:
-----------
ARGF.readlines will be passed the multiple file path.
Test Script:
{{{
require 'tempfile'
require 'test/unit/assertions.rb'
include Test::Unit::Assertions
t1 = Tempfile.new("foo")
t1.puts "1"
t1.puts "2"
t1.close
t2 = Tempfile.new("bar")
t2.puts "3"
t2.puts "4"
t2.close
def ruby(*args)
args = ['-e', '$>.write($<.read)'] if args.empty?
ruby = ARGV[0] || "/usr/local/bin/macruby"
f = IO.popen([ruby] + args, 'r+')
yield(f)
ensure
f.close unless !f || f.closed?
end
ruby('-e', "puts ARGF.readlines", t1.path, t2.path) do |f|
assert_equal("1\n2\n3\n4\n", f.read)
end
puts :ok
}}}
Modified Paths:
--------------
MacRuby/trunk/io.c
Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c 2010-11-16 03:05:59 UTC (rev 4908)
+++ MacRuby/trunk/io.c 2010-11-16 03:06:03 UTC (rev 4909)
@@ -3539,9 +3539,16 @@
static VALUE
argf_readlines(VALUE rcv, SEL sel, int argc, VALUE *argv)
{
- next_argv();
- ARGF_FORWARD(0, 0);
- return rb_io_readlines(ARGF.current_file, sel, argc, argv);
+ VALUE lines = rb_ary_new();
+ while (true) {
+ VALUE line = argf_getline(argf, sel, argc, argv);
+ if (NIL_P(line)) {
+ break;
+ }
+ rb_ary_push(lines, line);
+ }
+
+ return lines;
}
static VALUE
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101115/3a6ec0b6/attachment.html>
More information about the macruby-changes
mailing list