Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

String#ord

() -> ::Integer
ord → integer

Returns the integer ordinal of the first character of self:

Example
'h'.ord         # => 104
'hello'.ord     # => 104
'こんにちは'.ord  # => 12371

Related: see Converting to Non-String.

See also #oct #partition #next! #prepend also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0