Skip to content

Commit b7f65f0

Browse files
BurdetteLamarpeterzhu2118
authored andcommitted
[DOC] Tweaks for String#grapheme_clusters
1 parent a6aaeb9 commit b7f65f0

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

doc/string/grapheme_clusters.rdoc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
Returns an array of the grapheme clusters in +self+
22
(see {Unicode Grapheme Cluster Boundaries}[https://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries]):
33

4-
s = "\u0061\u0308-pqr-\u0062\u0308-xyz-\u0063\u0308" # => "ä-pqr-b̈-xyz-c̈"
4+
s = "ä-pqr-b̈-xyz-c̈"
5+
s.size # => 16
6+
s.bytesize # => 19
7+
s.grapheme_clusters.size # => 13
58
s.grapheme_clusters
69
# => ["ä", "-", "p", "q", "r", "-", "b̈", "-", "x", "y", "z", "-", "c̈"]
10+
11+
Details:
12+
13+
s = "ä"
14+
s.grapheme_clusters # => ["ä"] # One grapheme cluster.
15+
s.bytes # => [97, 204, 136] # Three bytes.
16+
s.chars # => ["a", "̈"] # Two characters.
17+
s.chars.map {|char| char.ord } # => [97, 776] # Their values.
18+
19+
Related: see {Converting to Non-String}[rdoc-ref:String@Converting+to+Non--5CString].

0 commit comments

Comments
 (0)