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#chr

() -> ::String
chr → string

Returns a string containing the first character of self:

Example
'hello'.chr     # => "h"
'こんにちは'.chr # => "こ"
''.chr          # => ""

Related: see Converting to New String.

See also #chop! #clear #chop #codepoints also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0