On 11/03/2009 11:32 PM, Hal Fulton wrote: > [Note: parts of this message were removed to make it a legal post.] ! >> 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). > Well, reopen also can take a string, I believe. So it already takes > more than one type. But the overhead argument is valid. The string is interpreted as a file name. With changing type I meant that a StringIO after #reopen (either with number, IO object or string as file name) must behave like an IO or File object which is a different type. I was not talking about the argument types to method #reopen but the type of the object itself. >> 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). >> >> > I'm not sure I understand. @x = StringIO.new "foo" def io; @x; end io.puts "foo" io.puts "another line" # later @x = File.open "log.txt" io.puts "this line goes to a completely different location" > How would I, for example, capture all that went to standard error > in a StringIO object? You can try to do $stderr = StringIO.new but this works only within the same process, i.e. not for sub processes. There is no way I am aware of to redirect a file descriptor to an in memory structure. If you want the redirection to work for a child process and get the data in the parent you need to use one of the popen family of methods. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/