[macruby-changes] [569] MacRuby/trunk/string.c

source_changes at macosforge.org source_changes at macosforge.org
Sun Sep 7 16:42:14 PDT 2008


Revision: 569
          http://trac.macosforge.org/projects/ruby/changeset/569
Author:   lsansonetti at apple.com
Date:     2008-09-07 16:42:14 -0700 (Sun, 07 Sep 2008)
Log Message:
-----------
define Symbol#<=>

Modified Paths:
--------------
    MacRuby/trunk/string.c

Modified: MacRuby/trunk/string.c
===================================================================
--- MacRuby/trunk/string.c	2008-09-06 23:18:28 UTC (rev 568)
+++ MacRuby/trunk/string.c	2008-09-07 23:42:14 UTC (rev 569)
@@ -4984,7 +4984,23 @@
     return Qfalse;
 }
 
+static VALUE
+sym_cmp(VALUE sym1, VALUE sym2)
+{
+    int code;
 
+    if (CLASS_OF(sym2) != rb_cSymbol)
+	return Qnil;
+    code = strcmp(RSYMBOL(sym1)->str, RSYMBOL(sym2)->str);
+    if (code > 0) {
+	code = 1;
+    }
+    else if (code < 0) {
+	code = -1;
+    }
+    return INT2FIX(code);
+}
+
 /*
  *  call-seq:
  *     sym.inspect    => string
@@ -5411,6 +5427,7 @@
     rb_define_singleton_method(rb_cSymbol, "all_symbols", rb_sym_all_symbols, 0); /* in parse.y */
 
     rb_define_method(rb_cSymbol, "==", sym_equal, 1);
+    rb_define_method(rb_cSymbol, "<=>", sym_cmp, 1);
     rb_define_method(rb_cSymbol, "inspect", sym_inspect, 0);
     rb_define_method(rb_cSymbol, "description", sym_inspect, 0);
     rb_define_method(rb_cSymbol, "dup", rb_obj_dup, 0);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080907/c6281a1b/attachment.html 


More information about the macruby-changes mailing list