Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Pathname#zero?
() -> bool
zero? → true or false
pathname_builtin.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/pathname_builtin.rb, line 2786
def zero?() FileTest.zero?(@path) end
Returns whether the entry at the path in self exists and has size zero.
The entry may be a file:
Example
pn = Pathname('/tmp/t.tmp') pn.write('foo') pn.zero? # => false pn.truncate(0) pn.zero? # => true pn.delete # Clean up.
The entry may be a directory:
Example
dir_pn = Pathname('/tmp/foo') dir_pn.mkdir dir_pn.children.size # => 0 # Size is filesystem-dependent; may or may not be zero. dir_pn.size # => 4096 dir_pn.zero? # => false file_pn = dir_pn / 't.tmp' # => #<Pathname:/tmp/foo/t.tmp> file_pn.write('foo') # Add a file. dir_pn.children.size # => 1 dir_pn.size # => 4096 dir_pn.zero? # => false dir_pn.rmtree
The entry may be neither of the above:
Example
Pathname('nosuch').zero? # => false