[macruby-changes] [3671] MacRuby/branches/icu/string.c

source_changes at macosforge.org source_changes at macosforge.org
Tue Mar 2 17:35:59 PST 2010


Revision: 3671
          http://trac.macosforge.org/projects/ruby/changeset/3671
Author:   lsansonetti at apple.com
Date:     2010-03-02 17:35:59 -0800 (Tue, 02 Mar 2010)
Log Message:
-----------
added #try_convert

Modified Paths:
--------------
    MacRuby/branches/icu/string.c

Modified: MacRuby/branches/icu/string.c
===================================================================
--- MacRuby/branches/icu/string.c	2010-03-03 01:33:12 UTC (rev 3670)
+++ MacRuby/branches/icu/string.c	2010-03-03 01:35:59 UTC (rev 3671)
@@ -1175,6 +1175,24 @@
 
 /*
  *  call-seq:
+ *     String.try_convert(obj) -> string or nil
+ *
+ *  Try to convert <i>obj</i> into a String, using to_str method.
+ *  Returns converted regexp or nil if <i>obj</i> cannot be converted
+ *  for any reason.
+ *
+ *     String.try_convert("str")     # => str
+ *     String.try_convert(/re/)      # => nil
+ */
+
+static VALUE
+rstr_try_convert(VALUE self, SEL sel, VALUE other)
+{
+    return rb_check_string_type(other);
+}
+
+/*
+ *  call-seq:
  *     String.new(str="")   => new_str
  *  
  *  Returns a new string object containing a copy of <i>str</i>.
@@ -3873,6 +3891,8 @@
     rb_const_set(rb_cObject, rb_intern("String"), rb_cRubyString);
 
     rb_objc_define_method(*(VALUE *)rb_cRubyString, "alloc", rstr_alloc, 0);
+    rb_objc_define_method(*(VALUE *)rb_cRubyString, "try_convert",
+	    rstr_try_convert, 1);
     rb_objc_define_method(rb_cRubyString, "initialize", rstr_initialize, -1);
     rb_objc_define_method(rb_cRubyString, "initialize_copy", rstr_replace, 1);
     rb_objc_define_method(rb_cRubyString, "dup", rstr_dup, 0);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100302/5a9c6baa/attachment-0001.html>


More information about the macruby-changes mailing list