Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is ruby's StringIO class really?

Tags:

io

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.

like image 427
John Dyer Avatar asked Jul 31 '09 09:07

John Dyer


1 Answers

no, StringIO is more similar to StringReader/StringWriter than StringBuffer.

In Java StringBuffer is the mutable version of String (since String is immutable).

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.

like image 171
dfa Avatar answered Jan 27 '23 12:01

dfa