使Ruby字符串的行为类似于文件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使Ruby字符串的行为类似于文件相关的知识,希望对你有一定的参考价值。

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'

以上是关于使Ruby字符串的行为类似于文件的主要内容,如果未能解决你的问题,请参考以下文章