Skip to content

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

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

  1. 3.0