Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
String#codepoints
() -> ::Array[::Integer]
() { (::Integer codepoint) -> void } -> self
codepoints → array_of_integers
string.c
View on GitHub ↗
static VALUE
rb_str_codepoints(VALUE str)
{
VALUE ary = WANTARRAY("codepoints", rb_str_strlen(str));
return rb_str_enumerate_codepoints(str, ary);
}
Returns an array of the codepoints in self; each codepoint is the integer value for a character:
Example
'hello'.codepoints # => [104, 101, 108, 108, 111] 'こんにちは'.codepoints # => [12371, 12435, 12395, 12385, 12399] ''.codepoints # => []
Related: see Converting to Non-String.