IO#try_convert will raise TypeError if the object does not return an IO from #to_io.
Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions
obj = Object.new
def obj.to_io
'foo'
end
assert_raise(TypeError){ IO.try_convert(obj) }
puts :ok
}}}
--- MacRuby/trunk/io.c 2011-03-04 07:40:52 UTC (rev 5249)
+++ MacRuby/trunk/io.c 2011-03-04 07:40:56 UTC (rev 5250)
@@ -3597,9 +3597,7 @@
static VALUE
rb_io_s_try_convert(VALUE dummy, SEL sel, VALUE obj)
{
- return rb_respond_to(obj, rb_intern("to_io"))
- ? rb_funcall3(obj, rb_intern("to_io"), 0, 0)
- : Qnil;
+ return rb_io_check_io(obj);
}
/*