summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mrblib/io.rb9
-rw-r--r--test/io.rb19
2 files changed, 28 insertions, 0 deletions
diff --git a/mrblib/io.rb b/mrblib/io.rb
index c838b96e5..4d2fda5f3 100644
--- a/mrblib/io.rb
+++ b/mrblib/io.rb
@@ -108,6 +108,11 @@ class IO
raise IOError
end
+ def <<(str)
+ write(str)
+ self
+ end
+
def eof?
return true if @buf && @buf.size > 0
@@ -136,6 +141,10 @@ class IO
seek(i, SEEK_SET)
end
+ def rewind
+ seek(0, SEEK_SET)
+ end
+
def seek(i, whence = SEEK_SET)
raise IOError if closed?
@pos = sysseek(i, whence)
diff --git a/test/io.rb b/test/io.rb
index b828fef49..a9bdc3e4f 100644
--- a/test/io.rb
+++ b/test/io.rb
@@ -150,6 +150,14 @@ assert('IO#write', '15.2.20.5.20') do
true
end
+assert('IO#<<') do
+ io = IO.open(IO.sysopen($mrbtest_io_wfname))
+ io << "" << ""
+ assert_equal 0, io.pos
+ io.close
+ true
+end
+
assert('IO.for_fd') do
fd = IO.sysopen($mrbtest_io_rfname)
io = IO.for_fd(fd)
@@ -248,6 +256,17 @@ assert('IO#pos=, IO#seek') do
io.closed?
end
+assert('IO#rewind') do
+ fd = IO.sysopen $mrbtest_io_rfname
+ io = IO.new fd
+ assert_equal 'm', io.getc
+ assert_equal 1, io.pos
+ assert_equal 0, io.rewind
+ assert_equal 0, io.pos
+ io.close
+ io.closed?
+end
+
assert('IO#gets') do
fd = IO.sysopen $mrbtest_io_rfname
io = IO.new fd