Skip to content

Commit 477db7c

Browse files
committedMar 6, 2016
Use keyword args in IO::{read,write}_nonblock instead of hash handling
1 parent bcbf8b6 commit 477db7c

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed
 

‎core/io.rb

+5-10
Original file line numberDiff line numberDiff line change
@@ -2046,15 +2046,10 @@ def read_all
20462046
#
20472047
# If the read buffer is not empty, read_nonblock reads from the
20482048
# buffer like readpartial. In this case, read(2) is not called.
2049-
def read_nonblock(size, buffer=nil, opts={})
2049+
def read_nonblock(size, buffer=nil, exception: true)
20502050
raise ArgumentError, "illegal read size" if size < 0
20512051
ensure_open
20522052

2053-
if buffer.is_a?(Hash)
2054-
opts = buffer
2055-
buffer = nil
2056-
end
2057-
20582053
buffer = StringValue buffer if buffer
20592054

20602055
if @ibuffer.size > 0
@@ -2064,7 +2059,7 @@ def read_nonblock(size, buffer=nil, opts={})
20642059
begin
20652060
str = read_if_available(size)
20662061
rescue EAGAINWaitReadable => exc
2067-
raise exc unless opts[:exception] == false
2062+
raise exc if exception
20682063

20692064
return :wait_readable
20702065
end
@@ -2073,7 +2068,7 @@ def read_nonblock(size, buffer=nil, opts={})
20732068
buffer.replace(str) if buffer
20742069
return str
20752070
else
2076-
raise EOFError, "stream closed" unless opts[:exception] == false
2071+
raise EOFError, "stream closed" if exception
20772072
end
20782073
end
20792074

@@ -2602,7 +2597,7 @@ def write(data)
26022597
data.bytesize
26032598
end
26042599

2605-
def write_nonblock(data, opts={})
2600+
def write_nonblock(data, exception: true)
26062601
ensure_open_and_writable
26072602

26082603
data = String data
@@ -2612,7 +2607,7 @@ def write_nonblock(data, opts={})
26122607

26132608
raw_write(data)
26142609
rescue EAGAINWaitWritable => exc
2615-
raise exc unless opts[:exception] == false
2610+
raise exc if exception
26162611

26172612
return :wait_writable
26182613
end

0 commit comments

Comments
 (0)
Please sign in to comment.