[macruby-changes] [4914] MacRuby/trunk/io.c

source_changes at macosforge.org source_changes at macosforge.org
Mon Nov 15 21:05:26 PST 2010


Revision: 4914
          http://trac.macosforge.org/projects/ruby/changeset/4914
Author:   watson1978 at gmail.com
Date:     2010-11-15 21:05:24 -0800 (Mon, 15 Nov 2010)
Log Message:
-----------
ARGF.chars .bytes .lines 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', <<-SRC, t1.path, t2.path) do |f|
  p ARGF.bytes.to_a
SRC
  assert_equal("[49, 10, 50, 10, 51, 10, 52, 10]\n", f.read)
end

ruby('-e', <<-SRC, t1.path, t2.path) do |f|
  p ARGF.chars.to_a
SRC
  assert_equal("[\"1\", \"\\n\", \"2\", \"\\n\", \"3\", \"\\n\", \"4\", \"\\n\"]\n", f.read)
end

ruby('-e', <<-SRC, t1.path, t2.path) do |f|
  p ARGF.lines.to_a
SRC
  assert_equal("[\"1\\n\", \"2\\n\", \"3\\n\", \"4\\n\"]\n", f.read)
end

puts :ok
}}}

Modified Paths:
--------------
    MacRuby/trunk/io.c

Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c	2010-11-16 05:05:19 UTC (rev 4913)
+++ MacRuby/trunk/io.c	2010-11-16 05:05:24 UTC (rev 4914)
@@ -4524,31 +4524,6 @@
 }
 
 static VALUE
-argf_lines(VALUE argf, SEL sel, int argc, VALUE *argv)
-{
-    next_argv();
-    ARGF_FORWARD(0, 0);
-    return rb_io_lines(ARGF.current_file, sel, argc, argv);
-}
-
-static VALUE
-argf_chars(VALUE argf, SEL sel)
-{
-    next_argv();
-    ARGF_FORWARD(0, 0);
-    return rb_io_chars(ARGF.current_file, sel);
-}
-
-static VALUE
-argf_bytes(VALUE argf, SEL sel)
-{
-    next_argv();
-    ARGF_FORWARD(0, 0);
-    return rb_io_bytes(ARGF.current_file, sel);
-}
-
-
-static VALUE
 argf_filename(VALUE argf, SEL sel)
 {
     next_argv();
@@ -4994,9 +4969,9 @@
     rb_objc_define_method(rb_cARGF, "each_line",  argf_each_line, -1);
     rb_objc_define_method(rb_cARGF, "each_byte",  argf_each_byte, 0);
     rb_objc_define_method(rb_cARGF, "each_char",  argf_each_char, 0);
-    rb_objc_define_method(rb_cARGF, "lines", argf_lines, -1);
-    rb_objc_define_method(rb_cARGF, "bytes", argf_bytes, 0);
-    rb_objc_define_method(rb_cARGF, "chars", argf_chars, 0);
+    rb_objc_define_method(rb_cARGF, "lines", argf_each_line, -1);
+    rb_objc_define_method(rb_cARGF, "bytes", argf_each_byte, 0);
+    rb_objc_define_method(rb_cARGF, "chars", argf_each_char, 0);
 
     rb_objc_define_method(rb_cARGF, "read",  argf_read, -1);
     rb_objc_define_method(rb_cARGF, "readpartial",  argf_readpartial, -1);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101115/bbcd89d1/attachment.html>


More information about the macruby-changes mailing list