Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

String#each_codepoint

str.each_codepoint {|integer| block } → str
str.each_codepoint → an_enumerator

Passes the Integer ordinal of each character in str, also known as a codepoint when applied to Unicode strings to the given block. For encodings other than UTF-8/UTF-16(BE|LE)/UTF-32(BE|LE), values are directly derived from the binary representation of each character.

If no block is given, an enumerator is returned instead.

Example
"hello\u0639".each_codepoint {|c| print c, ' ' }

produces:

104 101 108 108 111 1593