ord
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0 (0)
- 3.0.9 (-2)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
ord()
public
Returns the codepoint of the first character of the string, assuming a single-byte character encoding:
"a".ord # => 97 "Ã ".ord # => 224, in ISO-8859-1
This method is defined in Ruby 1.8 for Ruby 1.9 forward compatibility on these character encodings.
ActiveSupport::Multibyte::Chars#ord is forward compatible with Ruby 1.9 on UTF8 strings:
"a".mb_chars.ord # => 97 "Ã ".mb_chars.ord # => 224, in UTF8
Note that the 224 is different in both examples. In ISO-8859-1 “Ã ” is represented as a single byte, 224. In UTF8 it is represented with two bytes, namely 195 and 160, but its Unicode codepoint is 224. If we call ord on the UTF8 string “Ã ” the return value will be 195. That is not an error, because UTF8 is unsupported, the call itself would be bogus.