End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
IO#ready?
io.ready? → true or false
ext/io/wait/wait.c
View on GitHub ↗
static VALUE
io_ready_p(VALUE io)
{
rb_io_t *fptr;
#ifndef HAVE_RB_IO_WAIT
struct timeval tv = {0, 0};
#endif
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
if (rb_io_read_pending(fptr)) return Qtrue;
#ifndef HAVE_RB_IO_WAIT
if (wait_for_single_fd(fptr, RB_WAITFD_IN, &tv))
return Qtrue;
#else
if (RTEST(io_wait_event(io, RUBY_IO_READABLE, RB_INT2NUM(0))))
return Qtrue;
#endif
return Qfalse;
}
Returns true if input available without blocking, or false.