summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-io/mrblib
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2021-04-10 19:08:51 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2021-04-10 19:08:51 +0900
commit2cb9a0653aaa78c2897a89b680926f0caa819b37 (patch)
tree0f9fbb7f951bbc7946a8c6cd8e9cf51f44c9ae32 /mrbgems/mruby-io/mrblib
parent44d5e214cc63a5c55dc62db688edbb2040b4f828 (diff)
parent5cac9c847806707c4d651d3563e5723a7b4ccee7 (diff)
downloadmruby-2cb9a0653aaa78c2897a89b680926f0caa819b37.tar.gz
mruby-2cb9a0653aaa78c2897a89b680926f0caa819b37.zip
Merge branch 'io_getbyte' close #5389
Diffstat (limited to 'mrbgems/mruby-io/mrblib')
-rw-r--r--mrbgems/mruby-io/mrblib/io.rb18
1 files changed, 16 insertions, 2 deletions
diff --git a/mrbgems/mruby-io/mrblib/io.rb b/mrbgems/mruby-io/mrblib/io.rb
index 034f88529..a60562846 100644
--- a/mrbgems/mruby-io/mrblib/io.rb
+++ b/mrbgems/mruby-io/mrblib/io.rb
@@ -184,6 +184,11 @@ class IO
nil
end
+ def ungetbyte(substr)
+ substr = substr.chr if substr.is_a? Integer
+ ungetc substr
+ end
+
def read(length = nil, outbuf = "")
unless length.nil?
unless length.is_a? Integer
@@ -290,12 +295,21 @@ class IO
begin
readchar
rescue EOFError
- c = @buf[0]
- @buf[0,1]="" if c
nil
end
end
+ def readbyte
+ _read_buf
+ IO._bufread(@buf, 1).getbyte(0)
+ end
+
+ def getbyte
+ readbyte
+ rescue EOFError
+ nil
+ end
+
# 15.2.20.5.3
def each(&block)
return to_enum unless block