Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
File::Stat#owned?
() -> bool
owned? → true or false
file.c
View on GitHub ↗
static VALUE
rb_stat_owned(VALUE obj)
{
if (get_stat(obj)->ST_(uid) == geteuid()) return Qtrue;
return Qfalse;
}
Returns whether self represents a filesystem entry that, at the time self was created, existed and was owned by the user of the current process; see Snapshot:
Example
filepath = 'doc/t.tmp' File.write(filepath, 'foo') filestat = File.stat(filepath) filestat.owned? # => true File.delete(filepath) filestat.owned? # => true # Snapshot unchanged. dirpath = 'doc/tmp' Dir.mkdir(dirpath) dirstat = File.stat(dirpath) dirstat.owned? # => true Dir.rmdir(dirpath) dirstat.owned? # => true # Snapshot unchanged. File.stat('/etc').owned? # => false