ruby/doc/string/each_grapheme_cluster.rdoc

25 lines
744 B
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

With a block given, calls the given block with each successive grapheme cluster from +self+
(see {Unicode Grapheme Cluster Boundaries}[https://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries]);
returns +self+:
a = []
'hello'.each_grapheme_cluster do |grapheme_cluster|
a.push(grapheme_cluster)
end
a # => ["h", "e", "l", "l", "o"]
a = []
'тест'.each_grapheme_cluster do |grapheme_cluster|
a.push(grapheme_cluster)
end
a # => ["т", "е", "с", "т"]
a = []
'こんにちは'.each_grapheme_cluster do |grapheme_cluster|
a.push(grapheme_cluster)
end
a # => ["こ", "ん", "に", "ち", "は"]
With no block given, returns an enumerator.
Related: see {Iterating}[rdoc-ref:String@Iterating].