mruby-io: fix IO#ungetbyte; ref #5389

- remove `Integer#chr` (thus `mruby-sting-ext`) dependency
- fix the behavior when `c.is_a? String`
- fix the behavior when `c > 255`
This commit is contained in:
Yukihiro "Matz" Matsumoto
2021-04-13 07:24:56 +09:00
parent 9a9c842cb0
commit dd89a618b3
+9 -3
View File
@@ -184,9 +184,15 @@ class IO
nil
end
def ungetbyte(substr)
substr = substr.chr if substr.is_a? Integer
ungetc substr
def ungetbyte(c)
if c.is_a? String
c = c.getbyte(0)
else
c &= 0xff
end
s = " "
s.setbyte(0,c)
ungetc s
end
def read(length = nil, outbuf = "")