summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-io
diff options
context:
space:
mode:
authordearblue <[email protected]>2019-09-15 22:52:09 +0900
committerdearblue <[email protected]>2019-09-16 00:11:43 +0900
commit7cc8c7d2fff9b0dd629c8c614c4b066a4f490de4 (patch)
tree4ba5d3b2258eab8f3369d49c7e4977143881b688 /mrbgems/mruby-io
parent52a0ad4108d7b5f025c7f3def04649ea4fb56c1d (diff)
downloadmruby-7cc8c7d2fff9b0dd629c8c614c4b066a4f490de4.tar.gz
mruby-7cc8c7d2fff9b0dd629c8c614c4b066a4f490de4.zip
Small improvement for mruby-io
Diffstat (limited to 'mrbgems/mruby-io')
-rw-r--r--mrbgems/mruby-io/mrblib/io.rb14
1 files changed, 7 insertions, 7 deletions
diff --git a/mrbgems/mruby-io/mrblib/io.rb b/mrbgems/mruby-io/mrblib/io.rb
index eea6e923a..32bac1f0d 100644
--- a/mrbgems/mruby-io/mrblib/io.rb
+++ b/mrbgems/mruby-io/mrblib/io.rb
@@ -123,8 +123,8 @@ class IO
def write(string)
str = string.is_a?(String) ? string : string.to_s
- return str.size unless str.size > 0
- if 0 < @buf.length
+ return 0 if str.empty?
+ unless @buf.empty?
# reset real pos ignore buf
seek(pos, SEEK_SET)
end
@@ -141,7 +141,7 @@ class IO
_check_readable
begin
buf = _read_buf
- return buf.size == 0
+ return buf.empty?
rescue EOFError
return true
end
@@ -170,7 +170,7 @@ class IO
end
def _read_buf
- return @buf if @buf && @buf.size > 0
+ return @buf if @buf && @buf.bytesize > 0
@buf = sysread(BUF_SIZE)
end
@@ -255,12 +255,12 @@ class IO
if limit && limit <= @buf.size
array.push @buf[0, limit]
- @buf = @buf[limit, @buf.size - limit]
+ @buf[0, limit] = ""
break
elsif idx = @buf.index(rs)
len = idx + rs.size
array.push @buf[0, len]
- @buf = @buf[len, @buf.size - len]
+ @buf[0, len] = ""
break
else
array.push @buf
@@ -284,7 +284,7 @@ class IO
def readchar
_read_buf
c = @buf[0]
- @buf = @buf[1, @buf.size]
+ @buf[0] = ""
c
end