[macruby-changes] [1353] MacRuby/branches/experimental/io.c

source_changes at macosforge.org source_changes at macosforge.org
Sat Apr 4 15:43:14 PDT 2009


Revision: 1353
          http://trac.macosforge.org/projects/ruby/changeset/1353
Author:   pthomson at apple.com
Date:     2009-04-04 15:43:14 -0700 (Sat, 04 Apr 2009)
Log Message:
-----------
Implemented IO.try_convert.

Modified Paths:
--------------
    MacRuby/branches/experimental/io.c

Modified: MacRuby/branches/experimental/io.c
===================================================================
--- MacRuby/branches/experimental/io.c	2009-04-04 22:38:39 UTC (rev 1352)
+++ MacRuby/branches/experimental/io.c	2009-04-04 22:43:14 UTC (rev 1353)
@@ -264,24 +264,7 @@
 	return ((s == kCFStreamStatusNotOpen) || (s == kCFStreamStatusClosed));
 }
 
-/*
- *  call-seq:
- *     IO.try_convert(obj) -> io or nil
- *
- *  Try to convert <i>obj</i> into an IO, using to_io method.
- *  Returns converted IO or nil if <i>obj</i> cannot be converted
- *  for any reason.
- *
- *     IO.try_convert(STDOUT)     # => STDOUT
- *     IO.try_convert("STDOUT")   # => nil
- */
 static VALUE
-rb_io_s_try_convert(VALUE dummy, SEL sel, VALUE io)
-{
-rb_notimplement();
-}
-
-static VALUE
 io_alloc(VALUE klass, SEL sel)
 {
     struct RFile *io = ALLOC(struct RFile);
@@ -3022,8 +3005,29 @@
 rb_notimplement();
 }
 
+
 /*
  *  call-seq:
+ *     IO.try_convert(obj) -> io or nil
+ *
+ *  Try to convert <i>obj</i> into an IO, using to_io method.
+ *  Returns converted IO or nil if <i>obj</i> cannot be converted
+ *  for any reason.
+ *
+ *     IO.try_convert(STDOUT)     # => STDOUT
+ *     IO.try_convert("STDOUT")   # => nil
+ */
+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);
+}
+
+
+/*
+ *  call-seq:
  *     `cmd`    => string
  *
  *  Returns the standard output of running _cmd_ in a subshell.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090404/aab7265d/attachment.html>


More information about the macruby-changes mailing list