End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
String#each_char
str.each_char {|cstr| block } → str
str.each_char → an_enumerator
string.c
View on GitHub ↗
static VALUE
rb_str_each_char(VALUE str)
{
RETURN_SIZED_ENUMERATOR(str, 0, 0, rb_str_each_char_size);
return rb_str_enumerate_chars(str, 0);
}
Passes each character in str to the given block, or returns an enumerator if no block is given.
Example
"hello".each_char {|c| print c, ' ' }
produces:
Example
h e l l o
Ruby version changes
-
3.0
-
The following methods now return or yield
Stringinstances instead of subclass instances when called on subclass instances: [Bug #10845]
-
See also
#each_byte
#each_codepoint
#dump
#each_grapheme_cluster
also in
4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0