[DOC] Tweaks for String#each_codepoint

This commit is contained in:
BurdetteLamar 2025-07-22 18:44:04 -05:00 committed by Peter Zhu
parent cd9b74638c
commit 17eee25c66
2 changed files with 20 additions and 15 deletions

View file

@ -1,18 +1,23 @@
Calls the given block with each successive codepoint from +self+;
each codepoint is the integer value for a character;
With a block given, calls the block with each successive codepoint from +self+;
each {codepoint}[https://en.wikipedia.org/wiki/Code_point] is the integer value for a character;
returns +self+:
'hello'.each_codepoint {|codepoint| print codepoint, ' ' }
print "\n"
'тест'.each_codepoint {|codepoint| print codepoint, ' ' }
print "\n"
'こんにちは'.each_codepoint {|codepoint| print codepoint, ' ' }
print "\n"
a = []
'hello'.each_codepoint do |codepoint|
a.push(codepoint)
end
a # => [104, 101, 108, 108, 111]
a = []
'тест'.each_codepoint do |codepoint|
a.push(codepoint)
end
a # => [1090, 1077, 1089, 1090]
a = []
'こんにちは'.each_codepoint do |codepoint|
a.push(codepoint)
end
a # => [12371, 12435, 12395, 12385, 12399]
Output:
With no block given, returns an enumerator.
104 101 108 108 111
1090 1077 1089 1090
12371 12435 12395 12385 12399
Returns an enumerator if no block is given.
Related: see {Iterating}[rdoc-ref:String@Iterating].

View file

@ -9858,7 +9858,7 @@ rb_str_enumerate_codepoints(VALUE str, VALUE ary)
/*
* call-seq:
* each_codepoint {|integer| ... } -> self
* each_codepoint {|codepoint| ... } -> self
* each_codepoint -> enumerator
*
* :include: doc/string/each_codepoint.rdoc