Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
File::Stat#size?
() -> ::Integer?
stat.size? → Integer or nil
file.c
View on GitHub ↗
static VALUE
rb_stat_s(VALUE obj)
{
rb_off_t size = get_stat(obj)->st_size;
if (size == 0) return Qnil;
return OFFT2NUM(size);
}
Returns nil if stat is a zero-length file, the size of the file otherwise.
Example
File.stat("testfile").size? #=> 66 File.stat(File::NULL).size? #=> nil