Skip to content

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

class method · added in Ruby 3.3

Dir.for_fd

(::int) -> ::Dir
Dir.for_fd(fd) → dir

Returns a new Dir object representing the directory specified by the given integer directory file descriptor fd:

Example
d0 = Dir.new('..')
d1 = Dir.for_fd(d0.fileno)

Note that the returned d1 does not have an associated path:

Example
d0.path # => '..'
d1.path # => nil

This method uses the fdopendir() function defined by POSIX 2008; the method is not implemented on non-POSIX platforms (raises NotImplementedError).

Ruby version changes

  1. 3.3
See also .foreach .getwd .fchdir .glob also in 4.0 · 3.4 · 3.3