summaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-06-10 16:09:12 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-06-10 16:09:12 +0000
commitf9b1d4b174128bd92d35fe4b5b2556b57f799bfe (patch)
tree5b8bcc55cfadcc1a915199ad5f1601eee0f3e2f9 /string.c
parent9cb7e8d4a8269a2992232f535ab9e3561d7ecbe9 (diff)
downloadruby-f9b1d4b174128bd92d35fe4b5b2556b57f799bfe.tar.gz
ruby-f9b1d4b174128bd92d35fe4b5b2556b57f799bfe.tar.xz
ruby-f9b1d4b174128bd92d35fe4b5b2556b57f799bfe.zip
* ext/bigdecimal/lib/bigdecimal/newton.rb (Newton::nlsolve): typo
fixed: raize -> raise. [ruby-talk:196608] * string.c (rb_str_ord): new method. * parse.y (rbracket): allow optional newline before closing brackets. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@10242 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/string.c b/string.c
index 871fd9a70..2792e367d 100644
--- a/string.c
+++ b/string.c
@@ -4041,6 +4041,28 @@ rb_str_intern(VALUE s)
/*
* call-seq:
+ * str.ord => integer
+ *
+ * Return the <code>Integer</code> ordinal of a one-character string.
+ *
+ * "a".ord #=> 97
+ */
+
+VALUE
+rb_str_ord(VALUE s)
+{
+ int c;
+
+ if (RSTRING(s)->len != 1) {
+ rb_raise(rb_eTypeError,
+ "expacted a characer, but string of size %d given",
+ RSTRING(s)->len);
+ }
+ c = RSTRING(s)->ptr[0];
+ return INT2NUM(c);
+}
+/*
+ * call-seq:
* str.sum(n=16) => integer
*
* Returns a basic <em>n</em>-bit checksum of the characters in <i>str</i>,
@@ -4309,6 +4331,7 @@ Init_String(void)
rb_define_method(rb_cString, "crypt", rb_str_crypt, 1);
rb_define_method(rb_cString, "intern", rb_str_intern, 0);
rb_define_method(rb_cString, "to_sym", rb_str_intern, 0);
+ rb_define_method(rb_cString, "ord", rb_str_ord, 0);
rb_define_method(rb_cString, "include?", rb_str_include, 1);