Matt Armstrong wrote: > matz / ruby-lang.org (Yukihiro Matsumoto) writes: > >> Could you summarize pros and cons for filtering dot files (. and ..) >> from Dir.entries and Dir.each, please? > > This is from my memory of the thread. > > Pros: > > - Convenience -- you rarely need them, and often they get in the > way, requiring code like this over and over: > > next if ['.', '..'].include?(dir) > > - Portability -- some file systems don't have '.' and '..', so > code depending on it won't be as "portable." > > - The '.' and '..' are not _really_ a member of the directory. > They exist as an implementation artifact of the file system. > > Cons: > > - The '.' and '..' are returned as directory entries by the OS, so > Ruby should include them too. > > - If an application needs to have '.' and '..' included, it has to > add them manually. > > > Personally, I think filtering makes Ruby more convenient and so is a > good thing. > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ I agree with suggestions to provide two ways of accessing directory contents, that is, so that '.' and '..' show in listing or so that they do not show. My experience is that I usually do not need '.' and '..', though to not have a method to list them would be contrary to 'Least Surprise' to me (i.e. why can't I list the full directory contents?). My preference would be a single method that has a default argument. I would prefer that the default argument be set to list the true, complete directory contents (i.e. including '.' and '..'). This would remind me that I am specifically requesting to edit out '.' and '..' when I change that default argument. By having a single method, I could make the argument to it a parameter. If I wanted to modify code behaviour I could change the parameter in one place to modify behaviour thoughout the code. If I had two different methods to use, I would have to go through and change method everywhere (presuming method was used multiple places). I am not in agreement that '.' and '..' are not _really_ members of directory. They are members of directories (in UNIX(tm)). They have an inode number which can be seen by using 'ls -ia'; note that '.' and '..' have same inode number in root ('/') directory. In some UNIX (though it did not work for me on my Linux box) you can do 'cat .' and see the contents. ~mm