Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

IO#each_char

() { (::String c) -> void } -> self
() -> ::Enumerator[::String, self]
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.3 · 3.2 · 3.1 · 3.0