Write to a string : StringIO « File Directory « Ruby






Write to a string


require 'stringio'

s = StringIO.new
s.write('Treat it like a file.')
s.rewind
s.write("Act like it's")
s.string                             # => "Act like it's a file."

 








Related examples in the same category

1.Performing Random Access on Read-Once Input Streams
2.Pretending a String is a File
3.YAML.dump
4.Find the fifth byte
5.push data to string
6.Redirecting Standard Input or Output