Project

General

Profile

Actions

Feature #5479

closed

import StringIO into core, add String#to_io

Added by rkh (Konstantin Haase) over 12 years ago. Updated over 12 years ago.

Status:
Rejected
Assignee:
-
Target version:
[ruby-core:40312]

Description

Currently, a lot of APIs accept both String and IO instances. To differentiate what has been handed to those methods, the code often checks the object's class. However, from statements made by Matz at this years RubyConf it became clear that you should not rely on classes as contracts. Often, these projects wrap the String in a StringIO to avoid having two internal implementations.

It would be useful to add StringIO to core. This would allow adding a #to_io method to String (IO already implements #to_io).

An example use case:

WEBrick is one of those projects checking an objects class. Currently it is not possible to use Rails template streaming or the Sinatra streaming API with WEBrick, the de facto default server for both projects. If strings would implement #to_io, WEBrick would simply have to call #to_io on this. Rack/Sinatra/Rails could simply return an object that responds #to_io and in turn returns an object that behaves like IO, since creating a proper IO subclass that behaves properly and does not have a file handler is rather hard, especially if you want to support multiple Ruby versions (hence StringIO not inheriting from IO).


Files

noname (500 Bytes) noname Anonymous, 10/26/2011 02:23 AM
noname (500 Bytes) noname Anonymous, 10/26/2011 03:53 AM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0