Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Pathname#size?
() -> ::Integer?
size? → integer or nil
pathname_builtin.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/pathname_builtin.rb, line 2645
def size?() FileTest.size?(@path) end
Returns the size in bytes of the entry at the path in self if the entry exists and has non-zero size, nil otherwise:
Example
# Regular file. pn = Pathname('/tmp/t.tmp') pn.write('foo') pn.size? # => 3 # Non-zero size. pn.write('') pn.size? # => nil # Zero size. pn.delete # Clean up. pn.size? # => nil # Non-existent. # Directory. pn = Pathname('/tmp/foo/') pn.mkdir pn.size? # => 4096 # Non-zero size. pn.delete # Clean up. pn.size? # => nil # Non-existent.