Posted By

cczona on 03/13/08


Tagged

url file testing ruby io String open uri open-uri stringio


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

webstic


make Ruby strings behave like files


 / Published in: Ruby
 

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

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

  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'

Report this snippet  

You need to login to post a comment.