--HlL+5n6rz5pIUxbD
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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 protocol can actually be used. This is the only reason why I proposed moving StringIO to core. We could also add String#to_io as a monkey-patch to String in stringio in the stdlib.

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:

irb(main):001:0> require 'stringio'
=> true
irb(main):002:0> File.exist? 'hello!'
=> false
irb(main):003:0> class String; def to_io; StringIO.new self; end end
=> 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> 

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?

-- 
Aaron Patterson
http://tenderlovemaking.com/

--HlL+5n6rz5pIUxbD
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)

iQEcBAEBAgAGBQJOpwFyAAoJEJUxcLy0/6/GEfgH/iu2roypLAQt9eHSHvbkhZ21
+4IZ6TJQ09E+fJujoErDTBW5UT67ExsNRYMsPpyuG5YufvOXnYw6d2QlAlWzLU9U
MyBZ9cVXFC/Ot6PGMz1+3bzMhLOKo0z1W7rFFhRanV3ZIA0mltE5OvTkBsDzGoZe
v6NKSOiuYGtssmGYxD/+Ag3UZPimPMCNsWQ75MmeaAgTIBgcKKY8VxBtn+qLaYji
zpBVgo7q675zBi7ketLt9uQQE8mj9QqKh6RhOQ4PoFZYlihTHsrmSI2oPZ7JhMdS
OQ21gSXvDZ/0KbiXjKTYnnzMGczI0f1WQB+exM77kCMEWNjvhQ51O42RyZcqZME=0h
-----END PGP SIGNATURE-----

--HlL+5n6rz5pIUxbD--