Hi,
I often have a method which takes any kind of IO or something that
explicitly converts to a String.
def test(foo)
io = IO.try_convert(foo) || StringIO.new(String(foo))
...
end
Unfortunately this does not work with StringIO. StringIO does not
respond to #to_io which is used by #try_convert, and StringIO.new does
not accept StringIOs. #is_a?(StringIO) is false as well.
This messes everything up and the method from above becomes something
like this:
def test(foo)
io = IO.try_convert(foo) ||
foo.is_a?(StringIO) ? foo : StringIO.new(String(foo))
...
end
Is there another approach where StringIO behaves more like IO? What is
the reason that StringIO does not respond to #to_io?
Cheers,
Christian
···
--
ifu Hamburg - material flows and software
"We enable sustainable production."
ifu Hamburg GmbH
Max-Brauer-Allee 50 - 22765 Hamburg - Germany
fon: +49 40 480009-0 - fax: +49 40 480009-22 - email: info@ifu.com
Managing Director: Jan Hedemann - Commercial Register: Hamburg, HRB 52629
www.ifu.com - www.umberto.de - www.e-sankey.com