Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

IO#each_codepoint

() { (::Integer c) -> void } -> self
() -> ::Enumerator[::Integer, self]
each_codepoint {|c| ... } → self
each_codepoint → enumerator

Calls the given block with each codepoint in the stream; returns self:

Example
File.read('t.ja') # => "こんにちは"
f = File.new('t.ja')
a = []
f.each_codepoint {|c| a << c }
a # => [12371, 12435, 12395, 12385, 12399]
f.close

Returns an Enumerator if no block is given.

Related: IO#each_byte, IO#each_char.

See also #each_char #each_line #each_byte #echo= also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0