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

source_changes at macosforge.org source_changes at macosforge.org
Tue Mar 2 15:57:22 PST 2010


Revision: 3668
          http://trac.macosforge.org/projects/ruby/changeset/3668
Author:   lsansonetti at apple.com
Date:     2010-03-02 15:57:21 -0800 (Tue, 02 Mar 2010)
Log Message:
-----------
added #ord

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

Modified: MacRuby/branches/icu/string.c
===================================================================
--- MacRuby/branches/icu/string.c	2010-03-02 23:44:58 UTC (rev 3667)
+++ MacRuby/branches/icu/string.c	2010-03-02 23:57:21 UTC (rev 3668)
@@ -2577,6 +2577,24 @@
 
 /*
  *  call-seq:
+ *     str.ord   => integer
+ *  
+ *  Return the <code>Integer</code> ordinal of a one-character string.
+ *     
+ *     "a".ord         #=> 97
+ */
+
+static VALUE
+rstr_ord(VALUE str, SEL sel)
+{
+    if (RSTR(str)->length_in_bytes == 0) {
+	rb_raise(rb_eArgError, "empty string");
+    }
+    return INT2NUM(rb_str_get_uchar(str, 0));
+}
+
+/*
+ *  call-seq:
  *     str.chomp!(separator=$/)   => str or nil
  *  
  *  Modifies <i>str</i> in place as described for <code>String#chomp</code>,
@@ -3704,6 +3722,7 @@
     rb_objc_define_method(rb_cRubyString, "to_i", rstr_to_i, -1);
     rb_objc_define_method(rb_cRubyString, "hex", rstr_hex, 0);
     rb_objc_define_method(rb_cRubyString, "oct", rstr_oct, 0);
+    rb_objc_define_method(rb_cRubyString, "ord", rstr_ord, 0);
     rb_objc_define_method(rb_cRubyString, "chomp", rstr_chomp, -1);
     rb_objc_define_method(rb_cRubyString, "chomp!", rstr_chomp_bang, -1);
     rb_objc_define_method(rb_cRubyString, "sub", rstr_sub, -1);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100302/52c93046/attachment-0001.html>


More information about the macruby-changes mailing list