Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
File::Stat.new
(::path file_name) -> ::File::Stat
File::Stat.new(path) → stat
file.c
View on GitHub ↗
static VALUE
rb_stat_init(VALUE obj, VALUE fname)
{
rb_io_stat_data st;
FilePathValue(fname);
fname = rb_str_encode_ospath(fname);
if (STATX(StringValueCStr(fname), &st, STATX_ALL) == -1) {
rb_sys_fail_path(fname);
}
struct rb_stat *rb_st;
TypedData_Get_Struct(obj, struct rb_stat, &stat_data_type, rb_st);
rb_st->stat = st;
rb_st->initialized = true;
return Qnil;
}
Returns a new File::Stat object containing a snapshot of the filesystem entry at the given path:
Example
File::Stat.new('/etc/passwd') File::Stat.new('/tmp') File::Stat.new('nosuch') # Raises Errno::ENOENT: No such file or directory.