2009/11/3 Hal Fulton <rubyhacker / gmail.com>:
> By "Should it?" I mean "in the future" -- I'm not implying there's
> a bug now.

I don't think so.

> That is, I'm aware of how it works now. I'm just questioning whether
> it is worth changing.
>
> I believe it should be possible in theory to make it work -- though
> as I said, I haven't dig into the source.

This will be difficult to do because then StringIO would somehow have
to change its type.  Of course you could achieve that with some kind
of proxy pattern but I doubt that this would be a good idea; we all
would always pay the price of the overhead (1 more object per IO /
StringIO) for a feature which seems rarely wanted (I cannot recall
having seen a request like this in years).

The main purpose of reopen is to be able to reuse file descriptors
because there are some well known file descriptors (mainly 0,1 and 2)
which you might want to redirect for a sub process.

11:20:25 tmp$ ruby -e '$stdout.reopen("x"); exec "date"'
11:20:47 tmp$ cat x
Tue Nov  3 11:20:47 WEST 2009
11:20:53 tmp$ ruby -e '$stdout.reopen($stderr); exec "date"' >out 2>err
11:22:45 tmp$ cat out
11:22:47 tmp$ cat err
Tue Nov  3 11:22:45 WEST 2009
11:22:48 tmp$

That does not make much sense for a StringIO which is not connected to
any file descriptor - so you cannot reuse a file descriptor.  So for
StringIO the natural solution would be to just overwrite the variable
with another IO and make sure that there are no aliased variables
(e.g. by always referring to the single variable via a method).

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/