Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Integer#chr

chr → string
chr(encoding) → string

Returns a 1-character string containing the character represented by the value of self, according to the given encoding.

Example
65.chr                   # => "A"
0.chr                    # => "\x00"
255.chr                  # => "\xFF"
string = 255.chr(Encoding::UTF_8)
string.encoding          # => Encoding::UTF_8

Raises an exception if self is negative.

Related: Integer#ord.

See also #ceildiv #coerce #ceil #denominator also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0