stream.rewind
p stream.inspect
p stream.to_s
p stream.string
p stream.string.class
brains hgs 50 %> !$
StringIOtest.rb
“#StringIO:0xf11d8”
“#StringIO:0xf11d8”
" More text"
String
brains hgs 51 %>
Why not “a string. More text”?
If it is an extension of string should it not support the new to_str
method?
It’s not an extension. It’s a duck-extension
A platypus?
But yeah, I support the argument.
Gavin
Thank you,
Hugh
···
On Fri, 30 Apr 2004, Gavin Sinclair wrote:
On Friday, April 30, 2004, 3:30:54 AM, Hugh wrote:
Does this patch, as yet untested, provide a sufficient fix? I’m not
sure about the correct way to create ChangeLog entries, so hand
edited that with an approx time. (I believe I created this against
the 1.8 CVS, though I didn’t provide an exact release number to
the cvs update -d command done in the correct dir, so hope it
didn’t update from the head.)
That’s better, but I don’t see the part with which I initialized.
The default open mode is ‘w+’, so append occurs at file pos = 0.
So, like an existing file, your init. string gets overwritten.
try StringIO.new("text", 'a+') # or 'a'
Oh, I see what is happening now, I think. Thank you.
(Not defending, just observing
No problem.
Aside:
StringIO in CVS ( ruby 1.9.0 (2004-04-27) [i586-bccwin32] )
#-----
require ‘stringio’
sio = StringIO.new
STDOUT.reopen(sio) #-----
C:/TEMP/rb5226.TMP:5:in `reopen’: cannot convert StringIO into String (TypeError)
Is this because of the lack of to_str or because, to_s doesn’t give a
string, it gives a StringIO? I ran into this with .pack(“m*”)
for some StringIO x.
irb(main):009:0> x << ‘an example’
=> #StringIO:0x259ddf8
irb(main):010:0> .pack(‘m*’)
TypeError: cannot convert StringIO into String
from (irb):10:in `pack’
from (irb):10
irb(main):011:0>
So either this is a bug in pack because it doesn’t use metronomes –
I mean monotremes, or a bug in StringIO because to_s doesn’t do
“exactly what it says on the tin”. Unless my expectations are
wrong.
(I appreciate IO#reopen is undergoing changes; thanks)
Well, it may or may not be a platypus, but it’s certainly a monotreme.
That is only the second time I have heard that word, the first being
the song “Mammal” by They Might Be Giants.
On this musical theme:
p ‘monotreme’.sub(/(ono)(…)(e)/, ‘\3\2\1’)
daz
···
–
Could I just take this opportunity to say that the default open mode
for StringIO is ‘r+’ not ‘w+’ ?
‘w+’ would empty a string given to StringIO.new(string, ‘w+’).