Maybe another idea would be to introduce a Streamable protocol/class/module= , and add a to_stream method both to IO and StringIO. It could also ease im= plementing your own IO-like behavior. Konstantin On Oct 25, 2011, at 11:35 , Aaron Patterson wrote: > On Wed, Oct 26, 2011 at 02:22:21AM +0900, Haase, Konstantin wrote: >> My main request was to add String#to_io, as Aaron described, so this pro= tocol can actually be used. This is the only reason why I proposed moving S= tringIO to core. We could also add String#to_io as a monkey-patch to String= in stringio in the stdlib. >=20 > I really like this idea, but I'm kind of afraid of the consequences. > StringIO isn't a subclass of IO, and some things in ruby call `to_io` > then check the return type: >=20 > irb(main):001:0> require 'stringio' > =3D> true > irb(main):002:0> File.exist? 'hello!' > =3D> false > irb(main):003:0> class String; def to_io; StringIO.new self; end end > =3D> nil > irb(main):004:0> File.exist? 'hello!' > TypeError: can't convert String to IO (String#to_io gives StringIO) > from (irb):4:in `exist?' > from (irb):4 > from /Users/aaron/.local/bin/irb:12:in `<main>' > irb(main):005:0>=20 >=20 > I'm not sure which is best: convert StringIO to subclass IO, or find > these places that call `to_io` and fix them. Not to mention, how do we > "fix" the above example? What does `exists?` mean in terms of a > StringIO? >=20 > --=20 > Aaron Patterson > http://tenderlovemaking.com/