Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Pathname#opendir
() -> ::Dir
[U] () { (::Dir) -> U } -> U
opendir {|dir| ... } → object
opendir → dir
pathname_builtin.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/pathname_builtin.rb, line 2953
def opendir(&block) # :yield: dir
Dir.open(@path, &block)
end
Creates a Dir object dir for the directory at the path represented by self; opens dir.
With a block given, calls the block with dir; on block exit, closes dir and returns the block’s return value:
Example
pn = Pathname('.') pn.opendir {|dir| dir.entries.take(3) } # => ["README.md", "html", ".git"]
With no block given, returns the open directory dir:
Example
dir = pn.opendir # => #<Dir:.> dir.entries.take(3) # => ["README.md", "html", ".git"] dir.close