diff options
| author | take-cheeze <[email protected]> | 2021-03-27 02:20:25 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-04-10 19:08:14 +0900 |
| commit | bf455fd5829065db4f9f24a48ce823e3c497e402 (patch) | |
| tree | ee55a9166044c47afc21494f4d6b4110a4a91780 /mrbgems/mruby-io | |
| parent | 44d5e214cc63a5c55dc62db688edbb2040b4f828 (diff) | |
| download | mruby-bf455fd5829065db4f9f24a48ce823e3c497e402.tar.gz mruby-bf455fd5829065db4f9f24a48ce823e3c497e402.zip | |
Add IO#getbyte
Diffstat (limited to 'mrbgems/mruby-io')
| -rw-r--r-- | mrbgems/mruby-io/README.md | 4 | ||||
| -rw-r--r-- | mrbgems/mruby-io/mrblib/io.rb | 11 | ||||
| -rw-r--r-- | mrbgems/mruby-io/test/io.rb | 9 |
3 files changed, 22 insertions, 2 deletions
diff --git a/mrbgems/mruby-io/README.md b/mrbgems/mruby-io/README.md index db52c4a74..407cba65c 100644 --- a/mrbgems/mruby-io/README.md +++ b/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 | | | diff --git a/mrbgems/mruby-io/mrblib/io.rb b/mrbgems/mruby-io/mrblib/io.rb index 034f88529..d96bb2b23 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 @@ -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 diff --git a/mrbgems/mruby-io/test/io.rb b/mrbgems/mruby-io/test/io.rb index 328b5292f..88a89fee4 100644 --- a/mrbgems/mruby-io/test/io.rb +++ b/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 |
