multiple arguments to write

Make write methods of IO-like objects accept multiple arguments,
as well as IO#write.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60383 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-10-23 14:05:07 +00:00
parent 8bbdbf9e75
commit 30d23ec903
7 changed files with 10 additions and 9 deletions

View File

@ -339,7 +339,8 @@ module OpenSSL::Buffering
# Writes _s_ to the stream. If the argument is not a String it will be # Writes _s_ to the stream. If the argument is not a String it will be
# converted using +.to_s+ method. Returns the number of bytes written. # converted using +.to_s+ method. Returns the number of bytes written.
def write(s) def write(*s)
s = s.size == 1 ? s[0] : s.join("")
do_write(s) do_write(s)
s.bytesize s.bytesize
end end

View File

@ -160,7 +160,7 @@ module EnvUtil
def verbose_warning def verbose_warning
class << (stderr = "".dup) class << (stderr = "".dup)
alias write << alias write concat
end end
stderr, $stderr, verbose, $VERBOSE = $stderr, stderr, $VERBOSE, true stderr, $stderr, verbose, $VERBOSE = $stderr, stderr, $VERBOSE, true
yield stderr yield stderr

View File

@ -75,7 +75,7 @@ class TestLogDevice < Test::Unit::TestCase
# #
logdev = d(LogExcnRaiser.new) logdev = d(LogExcnRaiser.new)
class << (stderr = '') class << (stderr = '')
alias write << alias write concat
end end
$stderr, stderr = stderr, $stderr $stderr, stderr = stderr, $stderr
begin begin

View File

@ -49,11 +49,11 @@ module TestMkmf::Base
def filter(&block) def filter(&block)
@filter = block @filter = block
end end
def write(s) def write(*s)
if @out if @out
@buffer << s @buffer.concat(*s)
elsif @origin elsif @origin
@origin << s @origin.write(*s)
end end
end end
end end

View File

@ -14,7 +14,7 @@ class TestOptionParser::AutoConf < Test::Unit::TestCase
end end
class DummyOutput < String class DummyOutput < String
alias write << alias write concat
end end
def no_error(*args) def no_error(*args)
$stderr, stderr = DummyOutput.new, $stderr $stderr, stderr = DummyOutput.new, $stderr

View File

@ -14,7 +14,7 @@ class TestOptionParser::KwArg < Test::Unit::TestCase
end end
class DummyOutput < String class DummyOutput < String
alias write << alias write concat
end end
def assert_no_error(*args) def assert_no_error(*args)
$stderr, stderr = DummyOutput.new, $stderr $stderr, stderr = DummyOutput.new, $stderr

View File

@ -9,7 +9,7 @@ class TestOptionParser < Test::Unit::TestCase
end end
class DummyOutput < String class DummyOutput < String
alias write << alias write concat
end end
def assert_no_error(*args) def assert_no_error(*args)
$stderr, stderr = DummyOutput.new, $stderr $stderr, stderr = DummyOutput.new, $stderr