Why doesn't Ruby have a real StringBuffer or StringIO?

后端 未结 5 554
情话喂你
情话喂你 2020-12-09 07:25

I recently read a nice post on using StringIO in Ruby. What the author doesn\'t mention, though, is that StringIO is just an \"I.\" There\'s no \

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-09 08:03

    I looked at the ruby documentation for StringIO, and it looks like what you want is StringIO#string, not StringIO#to_s

    Thus, change your code to:

    s = StringIO.new
    s << 'foo'
    s << 'bar'
    s.string
    

提交回复
热议问题