Add IO#getbyte
MODIFY
mrbgems/mruby-io/README.md
mrbgems/mruby-io/README.md
@@ -59,7 +59,7 @@ Add the line below to your build configuration.
| IO#fileno, IO#to_i | o | |
| IO#flush | o | |
| IO#fsync | | |
-| IO#getbyte | | |
+| IO#getbyte | o | |
| IO#getc | o | |
| IO#gets | o | |
| IO#internal_encoding | | |
@@ -93,7 +93,7 @@ Add the line below to your build configuration.
| IO#sysseek | o | |
| IO#syswrite | o | |
| IO#to_io | | |
-| IO#ungetbyte | | |
+| IO#ungetbyte | o | |
| IO#ungetc | o | |
| IO#write | o | |
| IO#write_nonblock | | |

MODIFY
mrbgems/mruby-io/mrblib/io.rb
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
@@ -296,6 +301,12 @@ class IO
end
end
+ def getbyte
+ ret = getc
+ return ret.getbyte 0 if ret
+ ret
+ end
+
# 15.2.20.5.3
def each(&block)
return to_enum unless block

MODIFY
mrbgems/mruby-io/test/io.rb
mrbgems/mruby-io/test/io.rb
@@ -105,6 +105,15 @@ assert('IO#getc', '15.2.20.5.8') do
io.close
end
+assert('IO#getbyte') do
+ io = IO.new(IO.sysopen($mrbtest_io_rfname))
+ $mrbtest_io_msg.split("").each do |ch|
+ assert_equal ch.getbyte(0), io.getbyte
+ end
+ assert_equal nil, io.getbyte
+ io.close
+end
+
#assert('IO#gets', '15.2.20.5.9') do
#assert('IO#initialize_copy', '15.2.20.5.10') do
#assert('IO#print', '15.2.20.5.11') do

Add IO#getbyte