Skip to content

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

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̈"]
See also #getbyte #gsub #force_encoding #gsub! also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0