Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
File::Stat#size
() -> ::Integer
size → integer
file.c
View on GitHub ↗
static VALUE
rb_stat_size(VALUE self)
{
return OFFT2NUM(get_stat(self)->ST_(size));
}
Returns the size of self in bytes:
Example
File.stat('doc/maintainers.md').size # => 14900 # Regular file. File.stat('doc/syntax/').size # => 4096 # Directory. # When the file size changes. path = '/tmp/t.tmp' file = File.new(path, 'w+') file.write('foo') stat = File.stat(path) # Take snapshot. stat.size # => 3 file.write('bar') # Change file size. file.size # => 6 stat.size # => 3 # Snapshot unchanged. stat = File.stat(path) # Fresh snapshot. stat.size # => 6 # Shapshot different. # Clean up. file.close File.delete(path)