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

View file

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