Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
File.size
(::path | ::IO file_name) -> ::Integer
File.size(object) → integer
file.c
View on GitHub ↗
static VALUE
rb_file_s_size(VALUE klass, VALUE fname)
{
struct stat st;
if (rb_stat(fname, &st) < 0) {
int e = errno;
FilePathValue(fname);
rb_syserr_fail_path(e, fname);
}
return OFFT2NUM(st.st_size);
}
Returns the size in bytes of the given object, which may be a path or an IO object:
Example
File.size('doc/maintainers.md') # => 14900 # Regular file. File.size('doc/syntax/') # => 4096 # Directory. File.size($stdin) # => 0 # IO object.