Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Pathname#empty?
() -> bool
empty? → true or false
pathname_builtin.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/pathname_builtin.rb, line 2330
def empty?
if FileTest.directory?(@path)
Dir.empty?(@path)
else
File.empty?(@path)
end
end
Returns whether the entry represented by self exists and is empty:
Example
dir_pn = Pathname('example_dir') dir_pn.empty? # => false # Dir does not exist. dir_pn.mkdir dir_pn.empty? # => true # Dir exists and is empty. file_pn = Pathname('example_dir/example.txt') file_pn.empty? # => false # File does not exist. file_pn.write('') file_pn.empty? # => true # File exists and is empty. dir_pn.empty? # => false # Dir exists and is not empty. file_pn.write('foo') file_pn.empty? # => false # File exists and is not empty. file_pn.delete dir_pn.delete