我该如何清除一个
StringIO
实例?在我向字符串 io 中写入和读取之后,我想要将其清空。require "stringio"
io = StringIO.new
io.write("foo")
io.string #=> "foo"
# ... After doing something ...
io.string #=> Expecting ""
我尝试了flush
和rewind
,但仍然得到相同的内容。
io.string #=> "foo"; io.reopen(''); io.string #=> ""
。是吗? - Cary Swoveland