Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8980061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:59:18+00:00 2026-06-15T19:59:18+00:00

Dir -s seem awkward as compared to File -s. Many of the methods are

  • 0

Dir-s seem awkward as compared to File-s. Many of the methods are similar to IO methods, but a Dir doesn’t inherit from IO. For example, tell in the IO docs reads:

Returns the current offset (in bytes) of ios.

When read-ing and tell-ing through a normal Dir, I get large numbers like 346723732 and 422823816. I was originally expecting these integers to be more “array-like” and just be a simple range.

  • Are these the bytes of the files contained in the Dir?
  • If not, is there any meaning to the numbers returned like IO#tell?
  • Also why do Dir-s have an open and close function if they are not Streams?
  • Is it still just as important to close a Dir as a normal IO?

Any general explanation of how a Ruby Dir works would be appreciated.

update Another confusing part: if Dirs are not IOs, why does close raise an IOerror?

Closes the directory stream. Any further attempts to access dir will raise an IOError.

Also notice that in the documentation it considers it a “directory stream”. So this brings up the question again of are they streams or not and if not, why the naming convention?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:59:19+00:00Added an answer on June 15, 2026 at 7:59 pm

    So after some IRC chat here’s the conclusion I’ve come to:

    The Dir object is NOT an IO

    Dir Does not inherit from the IO class and is only readable. Still not sure why an IOError is raised on #close.

    An opened Dir IS a stream however

    Objects of class Dir are directory streams representing directories in the underlying file system.

    Also if you check the source for Dir#close You will see that it calls the C function dirclose. man dirclose prints:

    The closedir() function closes the directory stream associated with
    dirp. A successful call to closedir() also closes the underlying file
    descriptor associated with dirp. The directory stream descriptor dirp
    is not available after this call.

    …with dirp being a param.

    So yes, instantiated Dirs will open a stream and yes, Dirs will use a file descriptor and need to be closed if you do not want to rely on garbage collection.

    Big thanks to injekt and others on #ruby-lang irc!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can chroot with Dir.chroot Dir.chroot(/var/chroot/mychroot) But how can I return back from chroot?
I found some similar problems here on SO, but none seem to match my
This might seem a bit awkward but I want to start a console program
I deleted a file & package from my local source dir and I'm trying
I tried using gem install pg but it doesn't seem to work. gem install
I have searched many threads so far but cant seem to find a solution.
I am trying to delete all contents in specific folder but it doesn't seem
The Matlab functions exist() and dir() seem to ignore symlinks. Can you tell me
I have created a LWRP (my first time) but it doesn't seem to work
I can't seem to find in Xcode how can I add an include dir

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.