Skip to content

Commit 17eee25

Browse files
BurdetteLamarpeterzhu2118
authored andcommitted
[DOC] Tweaks for String#each_codepoint
1 parent cd9b746 commit 17eee25

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

doc/string/each_codepoint.rdoc

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
Calls the given block with each successive codepoint from +self+;
2-
each codepoint is the integer value for a character;
1+
With a block given, calls the block with each successive codepoint from +self+;
2+
each {codepoint}[https://en.wikipedia.org/wiki/Code_point] is the integer value for a character;
33
returns +self+:
44

5-
'hello'.each_codepoint {|codepoint| print codepoint, ' ' }
6-
print "\n"
7-
'тест'.each_codepoint {|codepoint| print codepoint, ' ' }
8-
print "\n"
9-
'こんにちは'.each_codepoint {|codepoint| print codepoint, ' ' }
10-
print "\n"
5+
a = []
6+
'hello'.each_codepoint do |codepoint|
7+
a.push(codepoint)
8+
end
9+
a # => [104, 101, 108, 108, 111]
10+
a = []
11+
'тест'.each_codepoint do |codepoint|
12+
a.push(codepoint)
13+
end
14+
a # => [1090, 1077, 1089, 1090]
15+
a = []
16+
'こんにちは'.each_codepoint do |codepoint|
17+
a.push(codepoint)
18+
end
19+
a # => [12371, 12435, 12395, 12385, 12399]
1120

12-
Output:
21+
With no block given, returns an enumerator.
1322

14-
104 101 108 108 111
15-
1090 1077 1089 1090
16-
12371 12435 12395 12385 12399
17-
18-
Returns an enumerator if no block is given.
23+
Related: see {Iterating}[rdoc-ref:String@Iterating].

string.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9858,7 +9858,7 @@ rb_str_enumerate_codepoints(VALUE str, VALUE ary)
98589858

98599859
/*
98609860
* call-seq:
9861-
* each_codepoint {|integer| ... } -> self
9861+
* each_codepoint {|codepoint| ... } -> self
98629862
* each_codepoint -> enumerator
98639863
*
98649864
* :include: doc/string/each_codepoint.rdoc

0 commit comments

Comments
 (0)