Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
String#grapheme_clusters
() -> ::Array[::String]
() { (::String grapheme_cluter) -> void } -> self
grapheme_clusters → array_of_grapheme_clusters
string.c
View on GitHub ↗
static VALUE
rb_str_grapheme_clusters(VALUE str)
{
VALUE ary = WANTARRAY("grapheme_clusters", rb_str_strlen(str));
return rb_str_enumerate_grapheme_clusters(str, ary);
}
Returns an array of the grapheme clusters in self (see Unicode Grapheme Cluster Boundaries):
Example
s = "\u0061\u0308-pqr-\u0062\u0308-xyz-\u0063\u0308" # => "ä-pqr-b̈-xyz-c̈" s.grapheme_clusters # => ["ä", "-", "p", "q", "r", "-", "b̈", "-", "x", "y", "z", "-", "c̈"]