Update ARGF.write interface

This commit is contained in:
Nobuyoshi Nakada 2024-04-04 18:22:27 +09:00
parent 64b0f4303e
commit 184db1fd6a
2 changed files with 8 additions and 6 deletions

10
io.c
View File

@ -14571,14 +14571,14 @@ argf_write_io(VALUE argf)
/* /*
* call-seq: * call-seq:
* ARGF.write(string) -> integer * ARGF.write(*objects) -> integer
* *
* Writes _string_ if inplace mode. * Writes each of the given +objects+ if inplace mode.
*/ */
static VALUE static VALUE
argf_write(VALUE argf, VALUE str) argf_write(int argc, VALUE *argv, VALUE argf)
{ {
return rb_io_write(argf_write_io(argf), str); return rb_io_writev(argf_write_io(argf), argc, argv);
} }
void void
@ -15823,7 +15823,7 @@ Init_IO(void)
rb_define_method(rb_cARGF, "binmode", argf_binmode_m, 0); rb_define_method(rb_cARGF, "binmode", argf_binmode_m, 0);
rb_define_method(rb_cARGF, "binmode?", argf_binmode_p, 0); rb_define_method(rb_cARGF, "binmode?", argf_binmode_p, 0);
rb_define_method(rb_cARGF, "write", argf_write, 1); rb_define_method(rb_cARGF, "write", argf_write, -1);
rb_define_method(rb_cARGF, "print", rb_io_print, -1); rb_define_method(rb_cARGF, "print", rb_io_print, -1);
rb_define_method(rb_cARGF, "putc", rb_io_putc, 1); rb_define_method(rb_cARGF, "putc", rb_io_putc, 1);
rb_define_method(rb_cARGF, "puts", rb_io_puts, -1); rb_define_method(rb_cARGF, "puts", rb_io_puts, -1);

View File

@ -1130,9 +1130,11 @@ class TestArgf < Test::Unit::TestCase
def test_puts def test_puts
t = make_tempfile("argf-#{__method__}", 'bar') t = make_tempfile("argf-#{__method__}", 'bar')
ruby('-pi-', '-W0', '-e', "print ARGF.puts('foo')", t.path) do |f| err = "#{@tmpdir}/errout"
ruby('-pi-', '-W2', '-e', "print ARGF.puts('foo')", t.path, {err: err}) do |f|
end end
assert_equal("foo\nbar\n", File.read(t.path)) assert_equal("foo\nbar\n", File.read(t.path))
assert_empty File.read(err)
end end
def test_print def test_print