ruby/doc/string/each_char.rdoc
2025-07-23 15:35:28 -04:00

22 lines
509 B
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

With a block given, calls the block with each successive character from +self+;
returns +self+:
a = []
'hello'.each_char do |char|
a.push(char)
end
a # => ["h", "e", "l", "l", "o"]
a = []
'тест'.each_char do |char|
a.push(char)
end
a # => ["т", "е", "с", "т"]
a = []
'こんにちは'.each_char do |char|
a.push(char)
end
a # => ["こ", "ん", "に", "ち", "は"]
With no block given, returns an enumerator.
Related: see {Iterating}[rdoc-ref:String@Iterating].