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'
  3.'acts like a file')
  4. puts sio.pos # => 0
  5. sio.pos= sio.length - 4
  6. puts # => 'file'


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.