Dir#empty? and File#empty?
I don't think it is a super-valuable addition (as nobody complained about it, or I can't find similar proposals), but seems logical to me:
# Existed since 2.4 Dir.empty?('dirname') #=> true/false File.empty?('filename') # => true/false # Proposed and implemented: Dir.open('dirname').empty? File.open('filename').empty?
Updated by shevegen (Robert A. Heiler) about 2 years ago
Personally I think I have wanted/needed this in the past. It has not been
that important to me to suggest it myself, though, but +1 on the name/API.
(as nobody complained about it, or I can't find similar proposals), but
seems logical to me:
I think not every thought process alone makes it into a suggestion. :)
A good example is require 'pp'; I was thinking that it would be convenient
before it was suggested to change it, but I never made a proposal myself.
Inertia sometimes wins ... but rubyists may often "think alike", or
in a somewhat similar way, to some extent.
I guess it (whether the API has not existed before) may have to do with what
is/should be possible through FileUtils. So perhaps the opinion is or was
that the file-related activities, directory-related activities etc... should
all go through FileUtils instead.
We already do have a few file-related activities outside of FileUtils,
though, such as File.delete(). I use the latter a lot, more often than
tapping into FileUtils or the .rm_rf variant (if the task is to delete
the file that is); oddly enough, one minor reason is so that I can avoid
having to do require 'fileutils', a bit similar as to how I like how
require 'pp' became optional - but anyway, I digress, so +1 to the
suggestion in itself.
(I have no particular opinion on the implementation either way; my comment
here is really meant to the Dir.empty?() and File.empty?() API/suggestion
Updated by zverok (Victor Shepelev) almost 2 years ago
This checks a directory named the current
Dirobject opened, instead of the opened directory itself.
I am not sure I understand (probably it is my lack of in-depth filesystem work understanding), for what I can tell, we have a directory object with some path, and check if directory with this path is empty?..