mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
[DOC] Tweaks for String#each_codepoint
This commit is contained in:
parent
cd9b74638c
commit
17eee25c66
2 changed files with 20 additions and 15 deletions
|
@ -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.
|
|
||||||
|
|
2
string.c
2
string.c
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue