make Ruby strings behave like files


/ Published in: Ruby
Save to your folder(s)

This is handy for testing, when you need to simulate an open file or open URI. Why, and the Pickaxe book, have better examples


Copy this code and paste it in your HTML
  1. require 'stringio'
  2.  
  3. sio=StringIO.new('acts like a file')
  4. puts sio.pos # => 0
  5. sio.pos= sio.length - 4
  6. puts sio.read # => 'file'

URL: http://whytheluckystiff.net/articles/rubyOneEightOh.html

Report this snippet


Comments


You need to login to view comments.