diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-06-10 16:09:12 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-06-10 16:09:12 +0000 |
commit | d1a5aa5685cfa12724116ce650cb5af3119cf103 (patch) | |
tree | 5b8bcc55cfadcc1a915199ad5f1601eee0f3e2f9 /string.c | |
parent | c053ad38cf8f92b64a0cc3e97d0accacd44df429 (diff) | |
download | ruby-d1a5aa5685cfa12724116ce650cb5af3119cf103.tar.gz |
* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@10242 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -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); |