[macruby-changes] [3682] MacRuby/branches/icu/re.cpp
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 3 12:31:56 PST 2010
Revision: 3682
http://trac.macosforge.org/projects/ruby/changeset/3682
Author: lsansonetti at apple.com
Date: 2010-03-03 12:31:56 -0800 (Wed, 03 Mar 2010)
Log Message:
-----------
added #try_convert
Modified Paths:
--------------
MacRuby/branches/icu/re.cpp
Modified: MacRuby/branches/icu/re.cpp
===================================================================
--- MacRuby/branches/icu/re.cpp 2010-03-03 20:28:52 UTC (rev 3681)
+++ MacRuby/branches/icu/re.cpp 2010-03-03 20:31:56 UTC (rev 3682)
@@ -265,6 +265,36 @@
/*
* call-seq:
+ * Regexp.try_convert(obj) -> re or nil
+ *
+ * Try to convert <i>obj</i> into a Regexp, using to_regexp method.
+ * Returns converted regexp or nil if <i>obj</i> cannot be converted
+ * for any reason.
+ *
+ * Regexp.try_convert(/re/) #=> /re/
+ * Regexp.try_convert("re") #=> nil
+ *
+ * o = Object.new
+ * Regexp.try_convert(o) #=> nil
+ * def o.to_regexp() /foo/ end
+ * Regexp.try_convert(o) #=> /foo/
+ *
+ */
+
+VALUE
+rb_check_regexp_type(VALUE re)
+{
+ return rb_check_convert_type(re, T_REGEXP, "Regexp", "to_regexp");
+}
+
+static VALUE
+regexp_try_convert(VALUE klass, SEL sel, VALUE obj)
+{
+ return rb_check_regexp_type(obj);
+}
+
+/*
+ * call-seq:
* Regexp.new(string [, options]) => regexp
* Regexp.new(regexp) => regexp
* Regexp.compile(string [, options]) => regexp
@@ -864,9 +894,9 @@
rb_objc_define_method(*(VALUE *)rb_cRegexp, "union", rb_reg_s_union_m, -2);
rb_objc_define_method(*(VALUE *)rb_cRegexp, "last_match",
rb_reg_s_last_match, -1);
+#endif
rb_objc_define_method(*(VALUE *)rb_cRegexp, "try_convert",
- rb_reg_s_try_convert, 1);
-#endif
+ (void *)regexp_try_convert, 1);
rb_objc_define_method(rb_cRegexp, "initialize",
(void *)regexp_initialize, -1);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100303/f0063bc5/attachment.html>
More information about the macruby-changes
mailing list