Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

IO#each_char

each_char {|c| ... } → self
each_char → enumerator

Calls the given block with each character in the stream; returns self. See Character IO.

Example
f = File.new('t.rus')
a = []
f.each_char {|c| a << c.ord }
a # => [1090, 1077, 1089, 1090]
f.close

Returns an Enumerator if no block is given.

Related: IO#each_byte, IO#each_codepoint.

See also #each_byte #each_codepoint #each #each_line also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0