On ruby-doc, the documentation entries for File::exist?
and File::exists?
are duplicated with different semantics: one entry says returns true
if file_name
is a directory; the other says returns true
if file_name
is a file.
I don't think either entry is correct. Both methods seem to be implemented in file.c
using rb_file_exist_p
, which, seems to try to call fstat()
if the value passed is an IO, or stat()
if it's a string. Both fstat()
and stat()
return 0
on success and -1
on error, and this is passed back to rb_file_exist_p
, and turned into a boolean result. It seems to me that
- there are two methods for making code read more easily; there are no semantic differences
- neither really relates to a file existing, but to whether a file-like item exists, e.g. a file, a dir, a socket, a fifo etc.
- perhaps the document could say that the methods tell the caller whether or not a thing that has file-like semantics is there, but more specific tests will tell what it actually is: e.g. directory?, file?, socket? etc.
Is my understanding of the (lack of) difference in the methods correct, and is it worth suggesting a change to the document ?