From: Aaron Patterson Date: 2011-10-26T03:35:36+09:00 Subject: [ruby-core:40367] Re: [ruby-trunk - Feature #5479] import StringIO into core, add String#to_io --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 prot= ocol can actually be used. This is the only reason why I proposed moving St= ringIO 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' =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 `
' irb(main):005:0>=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 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= =3D0h -----END PGP SIGNATURE----- --HlL+5n6rz5pIUxbD--