Skip to content

Commit 56572ba

Browse files
[DOC] Tweaks for String#each_grapheme_cluster (#13981)
1 parent e3d36ff commit 56572ba

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

doc/string/each_grapheme_cluster.rdoc

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
Calls the given block with each successive grapheme cluster from +self+
1+
With a block given, calls the given block with each successive grapheme cluster from +self+
22
(see {Unicode Grapheme Cluster Boundaries}[https://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries]);
33
returns +self+:
44

5-
s = "\u0061\u0308-pqr-\u0062\u0308-xyz-\u0063\u0308" # => "ä-pqr-b̈-xyz-c̈"
6-
s.each_grapheme_cluster {|gc| print gc, ' ' }
5+
a = []
6+
'hello'.each_grapheme_cluster do |grapheme_cluster|
7+
a.push(grapheme_cluster)
8+
end
9+
a # => ["h", "e", "l", "l", "o"]
710

8-
Output:
11+
a = []
12+
'тест'.each_grapheme_cluster do |grapheme_cluster|
13+
a.push(grapheme_cluster)
14+
end
15+
a # => ["т", "е", "с", "т"]
916

10-
ä - p q r - b̈ - x y z - c̈
17+
a = []
18+
'こんにちは'.each_grapheme_cluster do |grapheme_cluster|
19+
a.push(grapheme_cluster)
20+
end
21+
a # => ["こ", "ん", "に", "ち", "は"]
1122

12-
Returns an enumerator if no block is given.
23+
With no block given, returns an enumerator.
24+
25+
Related: see {Iterating}[rdoc-ref:String@Iterating].

string.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10029,7 +10029,7 @@ rb_str_enumerate_grapheme_clusters(VALUE str, VALUE ary)
1002910029

1003010030
/*
1003110031
* call-seq:
10032-
* each_grapheme_cluster {|gc| ... } -> self
10032+
* each_grapheme_cluster {|grapheme_cluster| ... } -> self
1003310033
* each_grapheme_cluster -> enumerator
1003410034
*
1003510035
* :include: doc/string/each_grapheme_cluster.rdoc

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy