问题描述
我认为我理解 StringIO
有点类似于Java的 StringBuffer
类,但我真的不明白它完全。你会如何在Ruby中定义它及其目的/可能的用途?只是希望能够澄清我的困惑。
I think I understand StringIO
somewhat as being similar to Java's StringBuffer
class, but I don't really understand it fully. How would you define it and its purpose/possible uses in Ruby? Just hoping to clear up my confusion.
推荐答案
不,更类似于 / 比。
no, StringIO is more similar to StringReader/StringWriter than StringBuffer.
在Java中是String的可变版本(因为String是不可变的)。
In Java StringBuffer is the mutable version of String (since String is immutable).
/ StringWriter是用于伪造文件访问时使用的方便类。您可以使用字符串使用与Reader / Writer相同的面向流的界面:它在单元测试中非常有用。
StringReader/StringWriter are handy classes meant to be used when you want to fake file access . You can read/write in a String with the same stream-oriented interface of Reader/Writer: it is immensely useful in unit testing.
这篇关于什么是ruby的StringIO类呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!