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#closed?

() -> bool
closed? → true or false

Returns true if the stream is closed for both reading and writing, false otherwise. See Open and Closed Streams.

Example
IO.popen('ruby', 'r+') do |pipe|
  puts pipe.closed?
  pipe.close_read
  puts pipe.closed?
  pipe.close_write
  puts pipe.closed?
end

Output:

Example
false
false
true

Related: IO#close_read, IO#close_write, IO#close.