mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
[DOC] Tweaks for String#each_byte
This commit is contained in:
parent
7ca3b38a95
commit
465b1696ad
1 changed files with 13 additions and 12 deletions
|
@ -1,17 +1,18 @@
|
||||||
Calls the given block with each successive byte from +self+;
|
With a block given, calls the block with each successive byte from +self+;
|
||||||
returns +self+:
|
returns +self+:
|
||||||
|
|
||||||
'hello'.each_byte {|byte| print byte, ' ' }
|
a = []
|
||||||
print "\n"
|
'hello'.each_byte {|byte| a.push(byte) } # Five 1-byte characters.
|
||||||
'тест'.each_byte {|byte| print byte, ' ' }
|
a # => [104, 101, 108, 108, 111]
|
||||||
print "\n"
|
a = []
|
||||||
'こんにちは'.each_byte {|byte| print byte, ' ' }
|
'тест'.each_byte {|byte| a.push(byte) } # Four 2-byte characters.
|
||||||
print "\n"
|
a # => [209, 130, 208, 181, 209, 129, 209, 130]
|
||||||
|
a = []
|
||||||
|
'こんにちは'.each_byte {|byte| a.push(byte) } # Five 3-byte characters.
|
||||||
|
a # => [227, 129, 147, 227, 130, 147, 227, 129, 171, 227, 129, 161, 227, 129, 175]
|
||||||
|
|
||||||
Output:
|
With no block given, returns an enumerator.
|
||||||
|
|
||||||
|
Related: see {Iterating}[rdoc-ref:String@Iterating].
|
||||||
|
|
||||||
104 101 108 108 111
|
|
||||||
209 130 208 181 209 129 209 130
|
|
||||||
227 129 147 227 130 147 227 129 171 227 129 161 227 129 175
|
|
||||||
|
|
||||||
Returns an enumerator if no block is given.
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue